├── README.md └── examples ├── blinkled ├── src │ ├── system.pas │ ├── linker.script │ ├── gpio.pas │ ├── kernel.pas │ └── stub.s └── build.sh ├── miniuart ├── src │ ├── system.pas │ ├── memmap │ ├── stub.s │ ├── gpio.pas │ ├── kernel.pas │ └── uart.pas └── build.sh ├── framebuf ├── src │ ├── memmap │ ├── stub.s │ ├── system.pas │ ├── gpio.pas │ ├── mailbox.pas │ ├── kernel.pas │ ├── uart.pas │ ├── fb.pas │ └── font.pas └── build.sh └── mailfirm ├── src ├── memmap ├── stub.s ├── system.pas ├── gpio.pas ├── mailbox.pas ├── kernel.pas └── uart.pas └── build.sh /README.md: -------------------------------------------------------------------------------- 1 | # fprpbm 2 | Bare Metal programming on the RaspberryPi using FreePascal 3 | 4 | Read the [Wiki](../../wiki) for documentation and tutorials. 5 | 6 | License: [Mozilla Public License 1.1](http://www.mozilla.org/MPL/) 7 | -------------------------------------------------------------------------------- /examples/blinkled/src/system.pas: -------------------------------------------------------------------------------- 1 | unit system; 2 | 3 | interface 4 | 5 | type 6 | cardinal = 0..$FFFFFFFF; 7 | hresult = cardinal; 8 | dword = cardinal; 9 | integer = longint; 10 | 11 | pchar = ^char; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /examples/miniuart/src/system.pas: -------------------------------------------------------------------------------- 1 | unit system; 2 | 3 | interface 4 | 5 | type 6 | cardinal = 0..$FFFFFFFF; 7 | hresult = cardinal; 8 | dword = cardinal; 9 | integer = longint; 10 | 11 | pchar = ^char; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /examples/framebuf/src/memmap: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x8000, LENGTH = 0x10000 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .rodata : { *(.rodata*) } > ram 11 | .bss : { *(.bss*) } > ram 12 | } 13 | -------------------------------------------------------------------------------- /examples/mailfirm/src/memmap: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x8000, LENGTH = 0x10000 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .rodata : { *(.rodata*) } > ram 11 | .bss : { *(.bss*) } > ram 12 | } 13 | -------------------------------------------------------------------------------- /examples/miniuart/src/memmap: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ram : ORIGIN = 0x8000, LENGTH = 0x10000 4 | } 5 | 6 | SECTIONS 7 | { 8 | .text : { *(.text*) } > ram 9 | .data : { *(.data*) } > ram 10 | .rodata : { *(.rodata*) } > ram 11 | .bss : { *(.bss*) } > ram 12 | } 13 | -------------------------------------------------------------------------------- /examples/framebuf/src/stub.s: -------------------------------------------------------------------------------- 1 | .globl _start 2 | _start: 3 | mov sp,#0x8000 4 | bl kmain 5 | hang: b hang 6 | 7 | .globl PUT32 8 | PUT32: 9 | str r1,[r0] 10 | bx lr 11 | 12 | .globl GET32 13 | GET32: 14 | ldr r0,[r0] 15 | bx lr 16 | 17 | .globl dummy 18 | dummy: 19 | bx lr 20 | 21 | -------------------------------------------------------------------------------- /examples/mailfirm/src/stub.s: -------------------------------------------------------------------------------- 1 | .globl _start 2 | _start: 3 | mov sp,#0x8000 4 | bl kmain 5 | hang: b hang 6 | 7 | .globl PUT32 8 | PUT32: 9 | str r1,[r0] 10 | bx lr 11 | 12 | .globl GET32 13 | GET32: 14 | ldr r0,[r0] 15 | bx lr 16 | 17 | .globl dummy 18 | dummy: 19 | bx lr 20 | 21 | -------------------------------------------------------------------------------- /examples/miniuart/src/stub.s: -------------------------------------------------------------------------------- 1 | .globl _start 2 | _start: 3 | mov sp,#0x8000 4 | bl kmain 5 | hang: b hang 6 | 7 | .globl PUT32 8 | PUT32: 9 | str r1,[r0] 10 | bx lr 11 | 12 | .globl GET32 13 | GET32: 14 | ldr r0,[r0] 15 | bx lr 16 | 17 | .globl dummy 18 | dummy: 19 | bx lr 20 | 21 | -------------------------------------------------------------------------------- /examples/blinkled/src/linker.script: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .init 0x0000 : { 4 | *(.init) 5 | } 6 | 7 | .text 0x8000 : 8 | { 9 | text = .; _text = .; __text = .; 10 | *(.text) 11 | } 12 | .data : 13 | { 14 | data = .; _data = .; __data = .; 15 | *(.data) 16 | kimage_text = .; 17 | LONG(text); 18 | kimage_data = .; 19 | LONG(data); 20 | kimage_end = .; 21 | LONG(end); 22 | } 23 | end = .; _end = .; __end = .; 24 | } 25 | -------------------------------------------------------------------------------- /examples/miniuart/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build Pascal Barebone OS 3 | # More Info: http://wiki.osdev.org/Pascal 4 | 5 | cd src 6 | 7 | #clean 8 | rm kernel 9 | rm *.o 10 | rm *.ppu 11 | rm *.elf 12 | rm *.img 13 | 14 | #build 15 | arm-none-eabi-as -I ./ stub.s -o stub.o 16 | 17 | fpc -Parm -Tlinux kernel.pas 18 | 19 | arm-none-eabi-ld --no-undefined stub.o system.o gpio.o uart.o kernel.o -Map kernel.map -o output.elf -T memmap 20 | 21 | arm-none-eabi-objcopy output.elf -O binary kernel.img 22 | arm-none-eabi-objdump -d output.elf > kernel.list 23 | 24 | cp *.img ../ 25 | 26 | cd .. 27 | -------------------------------------------------------------------------------- /examples/blinkled/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build Pascal Barebone OS 3 | # More Info: http://wiki.osdev.org/Pascal 4 | 5 | cd src 6 | 7 | #clean 8 | rm kernel 9 | rm *.o 10 | rm *.ppu 11 | rm *.elf 12 | rm *.img 13 | 14 | #build 15 | 16 | arm-none-eabi-as -I ./ stub.s -o stub.o 17 | 18 | fpc -Parm -Tlinux kernel.pas 19 | 20 | arm-none-eabi-ld --no-undefined stub.o system.o gpio.o kernel.o -Map kernel.map -o output.elf -T linker.script 21 | 22 | arm-none-eabi-objcopy output.elf -O binary kernel.img 23 | arm-none-eabi-objdump -d output.elf > kernel.list 24 | 25 | cp *.img ../ 26 | 27 | cd .. 28 | -------------------------------------------------------------------------------- /examples/mailfirm/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build Pascal Barebone OS 3 | # More Info: http://wiki.osdev.org/Pascal 4 | 5 | cd src 6 | 7 | #clean 8 | rm kernel 9 | rm *.o 10 | rm *.ppu 11 | rm *.elf 12 | rm *.img 13 | 14 | #build 15 | arm-none-eabi-as -I ./ stub.s -o stub.o 16 | 17 | fpc -Parm -Tlinux kernel.pas 18 | 19 | arm-none-eabi-ld --no-undefined stub.o system.o gpio.o uart.o mailbox.o kernel.o -Map kernel.map -o output.elf -T memmap 20 | 21 | arm-none-eabi-objcopy output.elf -O binary kernel.img 22 | arm-none-eabi-objdump -d output.elf > kernel.list 23 | 24 | cp *.img ../ 25 | 26 | cd .. 27 | -------------------------------------------------------------------------------- /examples/framebuf/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build Pascal Barebone OS 3 | # More Info: http://wiki.osdev.org/Pascal 4 | 5 | cd src 6 | 7 | #clean 8 | rm kernel 9 | rm *.o 10 | rm *.ppu 11 | rm *.elf 12 | rm *.img 13 | 14 | #build 15 | arm-none-eabi-as -I ./ stub.s -o stub.o 16 | 17 | fpc -Parm -Tlinux kernel.pas 18 | 19 | arm-none-eabi-ld --no-undefined stub.o system.o gpio.o uart.o mailbox.o fb.o font.o kernel.o -Map kernel.map -o output.elf -T memmap 20 | 21 | arm-none-eabi-objcopy output.elf -O binary kernel.img 22 | arm-none-eabi-objdump -d output.elf > kernel.list 23 | 24 | cp *.img ../ 25 | 26 | cd .. 27 | -------------------------------------------------------------------------------- /examples/blinkled/src/gpio.pas: -------------------------------------------------------------------------------- 1 | unit gpio; 2 | 3 | interface 4 | 5 | var 6 | GPFSEL1: ^LongWord; 7 | GPSET0: ^LongWord; 8 | GPCLR0: ^LongWord; 9 | 10 | procedure gpioinit; 11 | procedure okledenable(); 12 | procedure okledon(); 13 | procedure okledoff(); 14 | 15 | implementation 16 | 17 | procedure gpioinit(); 18 | begin 19 | GPFSEL1 := pointer($20200000+4); 20 | GPCLR0 := pointer($20200000+40); 21 | GPSET0 := pointer($20200000+28); 22 | end; 23 | 24 | procedure okledenable(); 25 | begin 26 | GPFSEL1^ := 1 shl 18; 27 | end; 28 | 29 | procedure okledon(); 30 | begin 31 | GPCLR0^ := 1 shl 16; 32 | end; 33 | 34 | procedure okledoff(); 35 | begin 36 | GPSET0^ := 1 shl 16; 37 | end; 38 | 39 | end. 40 | -------------------------------------------------------------------------------- /examples/framebuf/src/system.pas: -------------------------------------------------------------------------------- 1 | unit system; 2 | 3 | interface 4 | 5 | type 6 | cardinal = 0..$FFFFFFFF; 7 | hresult = cardinal; 8 | dword = cardinal; 9 | integer = longint; 10 | 11 | pchar = ^char; 12 | longstring = pchar; 13 | plongint = ^longint; 14 | 15 | const 16 | { Internal functions } 17 | fpc_in_chr_byte = 7; 18 | 19 | Function chr(b : byte) : Char; [INTERNPROC: fpc_in_chr_byte]; 20 | function strlen(p: pchar): longint; 21 | //Function Length (Const S : LongString) : Longint; 22 | 23 | implementation 24 | 25 | function strlen(p: pchar): longint; 26 | var i : longint; 27 | begin 28 | i:= 0; while p[i]<>#0 do inc(i); strlen:= i; exit; 29 | end; 30 | 31 | //Function Length (Const S : LongString) : Longint; 32 | //begin 33 | // Length:=PLongint(S)^; 34 | //end; 35 | 36 | end. 37 | -------------------------------------------------------------------------------- /examples/mailfirm/src/system.pas: -------------------------------------------------------------------------------- 1 | unit system; 2 | 3 | interface 4 | 5 | type 6 | cardinal = 0..$FFFFFFFF; 7 | hresult = cardinal; 8 | dword = cardinal; 9 | integer = longint; 10 | 11 | pchar = ^char; 12 | longstring = pchar; 13 | plongint = ^longint; 14 | 15 | const 16 | { Internal functions } 17 | fpc_in_chr_byte = 7; 18 | 19 | Function chr(b : byte) : Char; [INTERNPROC: fpc_in_chr_byte]; 20 | function strlen(p: pchar): longint; 21 | //Function Length (Const S : LongString) : Longint; 22 | 23 | implementation 24 | 25 | function strlen(p: pchar): longint; 26 | var i : longint; 27 | begin 28 | i:= 0; while p[i]<>#0 do inc(i); strlen:= i; exit; 29 | end; 30 | 31 | //Function Length (Const S : LongString) : Longint; 32 | //begin 33 | // Length:=PLongint(S)^; 34 | //end; 35 | 36 | end. 37 | -------------------------------------------------------------------------------- /examples/miniuart/src/gpio.pas: -------------------------------------------------------------------------------- 1 | unit gpio; 2 | 3 | interface 4 | 5 | var 6 | LGPFSEL1: ^LongWord; 7 | LGPSET0: ^LongWord; 8 | LGPCLR0: ^LongWord; 9 | ar: longword; 10 | 11 | procedure gpioinit; 12 | procedure okledenable(); 13 | procedure okledon(); 14 | procedure okledoff(); 15 | 16 | implementation 17 | 18 | procedure gpioinit(); 19 | begin 20 | LGPFSEL1 := pointer($20200000+4); 21 | LGPCLR0 := pointer($20200000+40); //0x28 22 | LGPSET0 := pointer($20200000+28); //0x1C 23 | end; 24 | 25 | procedure okledenable(); 26 | begin 27 | ar := LGPFSEL1^; 28 | ar := ar and not (7 shl 18); 29 | ar := ar or (1 shl 18); 30 | LGPFSEL1^:=ar; 31 | end; 32 | 33 | procedure okledon(); 34 | begin 35 | LGPCLR0^ := 1 shl 16; 36 | end; 37 | 38 | procedure okledoff(); 39 | begin 40 | LGPSET0^ := 1 shl 16; 41 | end; 42 | 43 | end. 44 | -------------------------------------------------------------------------------- /examples/framebuf/src/gpio.pas: -------------------------------------------------------------------------------- 1 | unit gpio; 2 | 3 | interface 4 | 5 | var 6 | LGPFSEL1: ^LongWord; 7 | LGPSET0: ^LongWord; 8 | LGPCLR0: ^LongWord; 9 | ar: longword; 10 | 11 | procedure gpioinit; 12 | procedure okledenable(); 13 | procedure okledon(); 14 | procedure okledoff(); 15 | procedure dummy ( value: longword ); external 'dummy'; 16 | 17 | implementation 18 | 19 | procedure gpioinit(); 20 | begin 21 | LGPFSEL1 := pointer($20200000+4); 22 | LGPCLR0 := pointer($20200000+40); //0x28 23 | LGPSET0 := pointer($20200000+28); //0x1C 24 | end; 25 | 26 | procedure okledenable(); 27 | begin 28 | ar := LGPFSEL1^; 29 | ar := ar and not (7 shl 18); 30 | ar := ar or (1 shl 18); 31 | LGPFSEL1^:=ar; 32 | end; 33 | 34 | procedure okledon(); 35 | begin 36 | LGPCLR0^ := 1 shl 16; 37 | end; 38 | 39 | procedure okledoff(); 40 | begin 41 | LGPSET0^ := 1 shl 16; 42 | end; 43 | 44 | end. 45 | -------------------------------------------------------------------------------- /examples/mailfirm/src/gpio.pas: -------------------------------------------------------------------------------- 1 | unit gpio; 2 | 3 | interface 4 | 5 | var 6 | LGPFSEL1: ^LongWord; 7 | LGPSET0: ^LongWord; 8 | LGPCLR0: ^LongWord; 9 | ar: longword; 10 | 11 | procedure gpioinit; 12 | procedure okledenable(); 13 | procedure okledon(); 14 | procedure okledoff(); 15 | procedure dummy ( value: longword ); external 'dummy'; 16 | 17 | implementation 18 | 19 | procedure gpioinit(); 20 | begin 21 | LGPFSEL1 := pointer($20200000+4); 22 | LGPCLR0 := pointer($20200000+40); //0x28 23 | LGPSET0 := pointer($20200000+28); //0x1C 24 | end; 25 | 26 | procedure okledenable(); 27 | begin 28 | ar := LGPFSEL1^; 29 | ar := ar and not (7 shl 18); 30 | ar := ar or (1 shl 18); 31 | LGPFSEL1^:=ar; 32 | end; 33 | 34 | procedure okledon(); 35 | begin 36 | LGPCLR0^ := 1 shl 16; 37 | end; 38 | 39 | procedure okledoff(); 40 | begin 41 | LGPSET0^ := 1 shl 16; 42 | end; 43 | 44 | end. 45 | -------------------------------------------------------------------------------- /examples/blinkled/src/kernel.pas: -------------------------------------------------------------------------------- 1 | { 2 | FreePascal RaspberyPi Bare Metal Kernel 3 | } 4 | 5 | unit kernel; 6 | 7 | interface 8 | 9 | uses gpio; 10 | 11 | procedure kmain(); stdcall; 12 | procedure rpiwait(); stdcall; external 'rpiwait'; 13 | procedure pwait(); 14 | 15 | implementation 16 | 17 | var 18 | flag: integer; 19 | wait: integer; 20 | 21 | procedure pwait(); 22 | //var wait: integer; //TODO with wait as var here things get unstable? 23 | begin 24 | wait := $3F000; 25 | repeat 26 | begin 27 | wait := wait -1; 28 | end; 29 | until wait = 0; 30 | end; 31 | 32 | procedure kmain(); stdcall; [public, alias: 'kmain']; 33 | begin 34 | flag := 0; 35 | 36 | gpioinit; //init memory for gpio 37 | okledenable(); //enable output on ok led 38 | 39 | while flag = 0 do //go into an endless loop 40 | begin 41 | okledon(); 42 | pwait(); 43 | 44 | okledoff(); 45 | pwait(); 46 | end; 47 | end; 48 | 49 | end. 50 | -------------------------------------------------------------------------------- /examples/miniuart/src/kernel.pas: -------------------------------------------------------------------------------- 1 | { 2 | FreePascal RaspberyPi Bare Metal Kernel 3 | } 4 | 5 | unit kernel; 6 | 7 | interface 8 | 9 | uses gpio, uart; 10 | 11 | procedure kmain(); stdcall; 12 | procedure pwait(); 13 | 14 | 15 | implementation 16 | 17 | var 18 | flag: integer; 19 | wait: integer; 20 | 21 | procedure pwait(); 22 | //var wait: integer; //TODO with wait as var here things get unstable? 23 | begin 24 | wait := $3F000; 25 | repeat 26 | begin 27 | wait := wait -1; 28 | end; 29 | until wait = 0; 30 | end; 31 | 32 | procedure kmain(); [public, alias: 'kmain']; 33 | begin 34 | flag := 0; 35 | 36 | gpioinit(); //init gpio 37 | okledenable(); //enable output on ok led 38 | 39 | uartinit(); //init uart 40 | 41 | 42 | 43 | okledon(); 44 | 45 | while flag = 0 do //go into an endless loop 46 | begin 47 | 48 | uart_putc('H'); 49 | uart_putc ( 'e' ); 50 | uart_putc ( 'l' ); 51 | uart_putc ( 'l' ); 52 | uart_putc ( 'o' ); 53 | //uart_putc ( ' ' ); //spatie werkt niet? 54 | 55 | //okledoff(); 56 | //pwait(); 57 | 58 | //okledon(); 59 | //pwait(); 60 | end; 61 | end; 62 | 63 | end. 64 | -------------------------------------------------------------------------------- /examples/mailfirm/src/mailbox.pas: -------------------------------------------------------------------------------- 1 | unit mailbox; 2 | 3 | interface 4 | 5 | uses gpio, uart; 6 | 7 | type 8 | tmb= array[0..7] of longword; 9 | 10 | var 11 | MAILBOX_READ: ^LongWord; 12 | MAILBOX_STATUS: ^LongWord; 13 | MAILBOX_WRITE: ^LongWord; 14 | MAILBOX_FULL: LongWord; 15 | MAILBOX_EMPTY: LongWord; 16 | data: LongWord; 17 | 18 | procedure mailboxinit(); 19 | procedure MailboxWrite(channel: longword; data: longword); 20 | function MailboxRead(channel: longword): longword; 21 | 22 | implementation 23 | 24 | procedure mailboxinit(); 25 | begin 26 | MAILBOX_READ := pointer($2000b880); 27 | MAILBOX_STATUS := pointer($2000b898); 28 | MAILBOX_WRITE := pointer($2000b8a0); 29 | MAILBOX_FULL := $80000000; 30 | MAILBOX_EMPTY := $40000000; 31 | end; 32 | 33 | procedure mailboxwrite(channel: longword; data: longword); 34 | begin 35 | while (boolean(MAILBOX_STATUS^ and MAILBOX_FULL)=true) do 36 | begin 37 | //do something; 38 | dummy(0); 39 | end; 40 | MAILBOX_WRITE^ := data or channel; 41 | end; 42 | 43 | function mailboxread(channel: longword): longword; 44 | begin 45 | data:=0; 46 | repeat 47 | begin 48 | while (boolean(MAILBOX_STATUS^ and MAILBOX_EMPTY)=true) do 49 | begin 50 | //do something 51 | dummy(0); 52 | end; 53 | data := MAILBOX_READ^; 54 | end; 55 | until ((data and 15) = channel); //15 is ongelijk aan $F 56 | mailboxread := data;//(data and $FFFFFFF0) shr 4; 57 | end; 58 | 59 | end. 60 | -------------------------------------------------------------------------------- /examples/framebuf/src/mailbox.pas: -------------------------------------------------------------------------------- 1 | unit mailbox; 2 | 3 | interface 4 | 5 | uses gpio, uart; 6 | 7 | type 8 | tmb= array[0..22] of longword; 9 | //tmb= array of longword; 10 | 11 | var 12 | MAILBOX_READ: ^LongWord; 13 | MAILBOX_STATUS: ^LongWord; 14 | MAILBOX_WRITE: ^LongWord; 15 | MAILBOX_FULL: LongWord; 16 | MAILBOX_EMPTY: LongWord; 17 | data: LongWord; 18 | 19 | procedure mailboxinit(); 20 | procedure MailboxWrite(channel: longword; data: longword); 21 | function MailboxRead(channel: longword): longword; 22 | 23 | implementation 24 | 25 | procedure mailboxinit(); 26 | begin 27 | MAILBOX_READ := pointer($2000b880); 28 | MAILBOX_STATUS := pointer($2000b898); 29 | MAILBOX_WRITE := pointer($2000b8a0); 30 | MAILBOX_FULL := $80000000; 31 | MAILBOX_EMPTY := $40000000; 32 | end; 33 | 34 | procedure mailboxwrite(channel: longword; data: longword); 35 | begin 36 | while (boolean(MAILBOX_STATUS^ and MAILBOX_FULL)=true) do 37 | begin 38 | //do something; 39 | dummy(0); 40 | end; 41 | MAILBOX_WRITE^ := (data and $fffffff0) or channel; 42 | end; 43 | 44 | function mailboxread(channel: longword): longword; 45 | begin 46 | data:=0; 47 | repeat 48 | begin 49 | while (boolean(MAILBOX_STATUS^ and MAILBOX_EMPTY)=true) do 50 | begin 51 | //do something 52 | dummy(0); 53 | end; 54 | data := MAILBOX_READ^; 55 | end; 56 | until ((data and 15) = channel); //15 is ongelijk aan $F 57 | mailboxread := data;//(data and $FFFFFFF0) shr 4; 58 | end; 59 | 60 | end. 61 | -------------------------------------------------------------------------------- /examples/mailfirm/src/kernel.pas: -------------------------------------------------------------------------------- 1 | { 2 | FreePascal RaspberyPi Bare Metal Kernel 3 | } 4 | 5 | unit kernel; 6 | 7 | interface 8 | 9 | uses gpio, uart, mailbox; 10 | 11 | procedure kmain(); stdcall; 12 | procedure pwait(); 13 | 14 | 15 | implementation 16 | 17 | var 18 | flag: integer; 19 | wait: integer; 20 | x, y, z: integer; 21 | mbtest: ^tmb; 22 | 23 | procedure pwait(); 24 | //var wait: integer; //TODO with wait as var here things get unstable? 25 | begin 26 | wait := $3F000; 27 | repeat 28 | begin 29 | wait := wait -1; 30 | end; 31 | until wait = 0; 32 | end; 33 | 34 | procedure kmain(); [public, alias: 'kmain']; 35 | begin 36 | flag := 0; 37 | 38 | gpioinit(); //init gpio 39 | okledenable(); //enable output on ok led 40 | 41 | uartinit(); //init uart 42 | 43 | mailboxinit(); 44 | 45 | mbtest := pointer($1000); 46 | 47 | mbtest^[0]:=8*4; //size 48 | mbtest^[1]:=0; //0 is request 49 | mbtest^[2]:=$40003; //display size tag 50 | mbtest^[3]:=8; //buffer size 51 | mbtest^[4]:=0; //request size 52 | mbtest^[5]:=0; //x 53 | mbtest^[6]:=0; //y 54 | mbtest^[7]:=0; //end tag 55 | 56 | mailboxwrite(8, $1000); //kan ik mbtest aan een specifiek adres toewijzen als $1000 57 | okledon(); 58 | ar := mailboxread(8); 59 | 60 | while flag = 0 do //go into an endless loop 61 | begin 62 | 63 | uart_puts( 'Hello World' ); 64 | uart_puts( makehex(30) ); 65 | 66 | uart_puts( makehex(mbtest^[5]) ); 67 | uart_puts('|'); 68 | uart_puts( makehex(mbtest^[6]) ); 69 | 70 | end; 71 | end; 72 | 73 | end. 74 | -------------------------------------------------------------------------------- /examples/blinkled/src/stub.s: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * main.s 3 | * by Alex Chadwick 4 | * 5 | * A sample assembly code implementation of the screen04 operating system, that 6 | * renders formatted text to the screen. 7 | * 8 | * main.s contains the main operating system, and IVT code. 9 | ******************************************************************************/ 10 | 11 | /* 12 | * .globl is a directive to our assembler, that tells it to export this symbol 13 | * to the elf file. Convention dictates that the symbol _start is used for the 14 | * entry point, so this all has the net effect of setting the entry point here. 15 | * Ultimately, this is useless as the elf itself is not used in the final 16 | * result, and so the entry point really doesn't matter, but it aids clarity, 17 | * allows simulators to run the elf, and also stops us getting a linker warning 18 | * about having no entry point. 19 | */ 20 | .section .init 21 | .globl _start 22 | _start: 23 | 24 | /* 25 | * According to the design of the RaspberryPi, addresses 0x00 through 0x20 26 | * actually have a special meaning. This is the location of the interrupt 27 | * vector table. Thus, we shouldn't make the code for our operating systems in 28 | * this area, as we will need it in the future. In fact the first address we are 29 | * really safe to use is 0x8000. 30 | */ 31 | b main 32 | 33 | /* 34 | * This command tells the assembler to put this code at 0x8000. 35 | */ 36 | .section .text 37 | 38 | 39 | 40 | /* 41 | * main is what we shall call our main operating system method. It never 42 | * returns, and takes no parameters. 43 | * C++ Signature: void main() 44 | */ 45 | main: 46 | 47 | /* 48 | * Start the pascal kernel. 49 | */ 50 | .extern kmain 51 | bl kmain 52 | 53 | loop$: 54 | b loop$ 55 | 56 | .global rpiwait 57 | rpiwait: 58 | mov r2,#0x3F0000 59 | wait1$: 60 | sub r2,#1 61 | cmp r2,#0 62 | bne wait1$ 63 | mov pc,lr 64 | -------------------------------------------------------------------------------- /examples/framebuf/src/kernel.pas: -------------------------------------------------------------------------------- 1 | { 2 | FreePascal RaspberyPi Bare Metal Kernel 3 | } 4 | 5 | unit kernel; 6 | 7 | interface 8 | 9 | uses gpio, uart, mailbox, fb; 10 | 11 | procedure kmain(); stdcall; 12 | procedure pwait(); 13 | 14 | 15 | implementation 16 | 17 | var 18 | flag: integer; 19 | wait: integer; 20 | //x, y, z: integer; 21 | mbtest: ^tmb; 22 | width, height: longword; 23 | 24 | procedure pwait(); 25 | //var wait: integer; //TODO with wait as var here things get unstable? 26 | begin 27 | wait := $3F000; 28 | repeat 29 | begin 30 | wait := wait -1; 31 | end; 32 | until wait = 0; 33 | end; 34 | 35 | procedure kmain(); [public, alias: 'kmain']; 36 | begin 37 | flag := 0; 38 | 39 | gpioinit(); //init gpio 40 | okledenable(); //enable output on ok led 41 | 42 | uartinit(); //init uart 43 | 44 | mailboxinit(); 45 | 46 | mbtest := pointer($1000); 47 | 48 | //header 49 | mbtest^[0]:=8*4; //size 50 | mbtest^[1]:=0; //0 is request 51 | //start record 52 | mbtest^[2]:=$40003; //display size tag 53 | mbtest^[3]:=8; //size of the response buffer 54 | mbtest^[4]:=0; //size of the request 55 | //start of request/response 56 | mbtest^[5]:=0; //x 57 | mbtest^[6]:=0; //y 58 | //end record 59 | mbtest^[7]:=0; //end tag 60 | 61 | mailboxwrite(8, $1000); //kan ik mbtest aan een specifiek adres toewijzen als $1000 62 | 63 | ar := mailboxread(8); 64 | width:= mbtest^[5]; 65 | height:= mbtest^[6]; 66 | 67 | okledon(); 68 | 69 | framebufferinit(); 70 | framebufferfillscreen(); 71 | 72 | 73 | while flag = 0 do //go into an endless loop 74 | begin 75 | 76 | uart_puts( ' read res ' ); 77 | //uart_puts( makehex(ar) ); 78 | // uart_puts( pchar(makehex( mbtest^[1] )) ); 79 | // uart_puts( pchar(makehex( mbtest^[4] )) ); 80 | 81 | uart_puts( makehex( width ) ); 82 | uart_puts('|'); 83 | uart_puts( makehex( height ) ); 84 | 85 | uart_puts( ' end read res ' ); 86 | 87 | fbdebug(); 88 | 89 | end; 90 | end; 91 | 92 | end. 93 | -------------------------------------------------------------------------------- /examples/miniuart/src/uart.pas: -------------------------------------------------------------------------------- 1 | unit uart; 2 | 3 | interface 4 | 5 | uses gpio; 6 | 7 | var 8 | 9 | GPFSEL1 : LongWord; 10 | GPSET0 : LongWord; 11 | GPCLR0 : LongWord; 12 | 13 | GPPUD : LongWord; 14 | GPPUDCLK0 : LongWord; 15 | 16 | AUX_ENABLES : LongWord; 17 | AUX_MU_IO_REG : LongWord; 18 | AUX_MU_IER_REG : LongWord; 19 | AUX_MU_IIR_REG : LongWord; 20 | AUX_MU_LCR_REG : LongWord; 21 | AUX_MU_MCR_REG : LongWord; 22 | AUX_MU_LSR_REG : LongWord; 23 | AUX_MU_MSR_REG : LongWord; 24 | AUX_MU_SCRATCH : LongWord; 25 | AUX_MU_CNTL_REG : LongWord; 26 | AUX_MU_STAT_REG : LongWord; 27 | AUX_MU_BAUD_REG : LongWord; 28 | 29 | ar: longword; 30 | 31 | procedure uartinit(); 32 | procedure uart_putc( c: char ); 33 | 34 | procedure PUT32 ( address: longword; value:longword ); external 'PUT32'; 35 | function GET32 ( address: longword ): longword; external 'GET32'; 36 | procedure dummy ( value: longword ); external 'dummy'; 37 | 38 | implementation 39 | 40 | procedure uartinit(); 41 | begin 42 | 43 | GPFSEL1 := $20200004; 44 | GPSET0 := $2020001C; 45 | GPCLR0 := $20200028; 46 | 47 | GPPUD := $20200094; 48 | GPPUDCLK0 := $20200098; 49 | 50 | AUX_ENABLES := $20215004; 51 | AUX_MU_IO_REG := $20215040; 52 | AUX_MU_IER_REG := $20215044; 53 | AUX_MU_IIR_REG := $20215048; 54 | AUX_MU_LCR_REG := $2021504C; 55 | AUX_MU_MCR_REG := $20215050; 56 | AUX_MU_LSR_REG := $20215054; 57 | AUX_MU_MSR_REG := $20215058; 58 | AUX_MU_SCRATCH := $2021505C; 59 | AUX_MU_CNTL_REG := $20215060; 60 | AUX_MU_STAT_REG := $20215064; 61 | AUX_MU_BAUD_REG := $20215068; 62 | 63 | PUT32(AUX_ENABLES,1); 64 | PUT32(AUX_MU_IER_REG,0); 65 | PUT32(AUX_MU_CNTL_REG,0); 66 | PUT32(AUX_MU_LCR_REG,3); 67 | PUT32(AUX_MU_MCR_REG,0); 68 | PUT32(AUX_MU_IER_REG,0); 69 | PUT32(AUX_MU_IIR_REG,$C6); 70 | PUT32(AUX_MU_BAUD_REG,270); 71 | 72 | ar := GET32(GPFSEL1); 73 | ar := ar and not (7 shl 12); 74 | ar := ar or (2 shl 12); 75 | PUT32(GPFSEL1,ar); 76 | 77 | PUT32(GPPUD,0); 78 | for ar:=0 to 149 do dummy(ar); 79 | PUT32(GPPUDCLK0,(1 shl 14)); 80 | for ar:=0 to 149 do dummy(ar); 81 | PUT32(GPPUDCLK0,0); 82 | PUT32(AUX_MU_CNTL_REG,2); 83 | 84 | end; 85 | 86 | procedure uart_putc( c: char ); 87 | begin 88 | while(true) do 89 | begin 90 | if boolean(GET32(AUX_MU_LSR_REG) and $20)=true then break; 91 | end; 92 | PUT32(AUX_MU_IO_REG,longword(c)); 93 | end; 94 | 95 | end. 96 | -------------------------------------------------------------------------------- /examples/framebuf/src/uart.pas: -------------------------------------------------------------------------------- 1 | unit uart; 2 | 3 | interface 4 | 5 | uses gpio; 6 | 7 | var 8 | 9 | GPFSEL1 : LongWord; 10 | GPSET0 : LongWord; 11 | GPCLR0 : LongWord; 12 | 13 | GPPUD : LongWord; 14 | GPPUDCLK0 : LongWord; 15 | 16 | AUX_ENABLES : LongWord; 17 | AUX_MU_IO_REG : LongWord; 18 | AUX_MU_IER_REG : LongWord; 19 | AUX_MU_IIR_REG : LongWord; 20 | AUX_MU_LCR_REG : LongWord; 21 | AUX_MU_MCR_REG : LongWord; 22 | AUX_MU_LSR_REG : LongWord; 23 | AUX_MU_MSR_REG : LongWord; 24 | AUX_MU_SCRATCH : LongWord; 25 | AUX_MU_CNTL_REG : LongWord; 26 | AUX_MU_STAT_REG : LongWord; 27 | AUX_MU_BAUD_REG : LongWord; 28 | 29 | ar, rb, rc: longword; 30 | i: longword; 31 | digits: pchar; 32 | pos: longword; 33 | 34 | procedure uartinit(); 35 | procedure uart_putc( c: longword ); 36 | procedure uart_puts( s: pchar ); 37 | 38 | procedure PUT32 ( address: longword; value:longword ); external 'PUT32'; 39 | function GET32 ( address: longword ): longword; external 'GET32'; 40 | Function makehex(val: longword): pchar; 41 | 42 | 43 | implementation 44 | 45 | procedure uartinit(); 46 | begin 47 | 48 | GPFSEL1 := $20200004; 49 | GPSET0 := $2020001C; 50 | GPCLR0 := $20200028; 51 | 52 | GPPUD := $20200094; 53 | GPPUDCLK0 := $20200098; 54 | 55 | AUX_ENABLES := $20215004; 56 | AUX_MU_IO_REG := $20215040; 57 | AUX_MU_IER_REG := $20215044; 58 | AUX_MU_IIR_REG := $20215048; 59 | AUX_MU_LCR_REG := $2021504C; 60 | AUX_MU_MCR_REG := $20215050; 61 | AUX_MU_LSR_REG := $20215054; 62 | AUX_MU_MSR_REG := $20215058; 63 | AUX_MU_SCRATCH := $2021505C; 64 | AUX_MU_CNTL_REG := $20215060; 65 | AUX_MU_STAT_REG := $20215064; 66 | AUX_MU_BAUD_REG := $20215068; 67 | 68 | PUT32(AUX_ENABLES,1); 69 | PUT32(AUX_MU_IER_REG,0); 70 | PUT32(AUX_MU_CNTL_REG,0); 71 | PUT32(AUX_MU_LCR_REG,3); 72 | PUT32(AUX_MU_MCR_REG,0); 73 | PUT32(AUX_MU_IER_REG,0); 74 | PUT32(AUX_MU_IIR_REG,$C6); 75 | PUT32(AUX_MU_BAUD_REG,270); 76 | 77 | ar := GET32(GPFSEL1); 78 | ar := ar and not (7 shl 12); 79 | ar := ar or (2 shl 12); 80 | PUT32(GPFSEL1,ar); 81 | 82 | PUT32(GPPUD,0); 83 | for ar:=0 to 149 do dummy(ar); 84 | PUT32(GPPUDCLK0,(1 shl 14)); 85 | for ar:=0 to 149 do dummy(ar); 86 | PUT32(GPPUDCLK0,0); 87 | PUT32(AUX_MU_CNTL_REG,2); 88 | 89 | end; 90 | 91 | procedure uart_putc( c: longword ); 92 | begin 93 | while(true) do 94 | begin 95 | if boolean(GET32(AUX_MU_LSR_REG) and $20)=true then break; 96 | end; 97 | PUT32(AUX_MU_IO_REG,longword(c)); 98 | end; 99 | 100 | Function makehex(val: longword): pchar; 101 | begin 102 | makehex:=''; 103 | pos:=0; 104 | 105 | rb:=32+4; 106 | while(true) do 107 | begin 108 | rb := rb - 4; 109 | rc := (val shr rb) and $F; 110 | if(rc>9) then rc := rc + $37 else rc := rc +$30; 111 | makehex[pos] := chr(rc); 112 | pos:=pos+1; 113 | if(rb=0) then break; 114 | end; 115 | makehex[pos] := chr($20); 116 | end; 117 | 118 | procedure uart_puts( s: pchar ); 119 | begin 120 | for i := 0 to strlen(s)-1 do 121 | begin 122 | uart_putc( longword(char(s[i])) ); 123 | end; 124 | end; 125 | 126 | end. 127 | -------------------------------------------------------------------------------- /examples/mailfirm/src/uart.pas: -------------------------------------------------------------------------------- 1 | unit uart; 2 | 3 | interface 4 | 5 | uses gpio; 6 | 7 | var 8 | 9 | GPFSEL1 : LongWord; 10 | GPSET0 : LongWord; 11 | GPCLR0 : LongWord; 12 | 13 | GPPUD : LongWord; 14 | GPPUDCLK0 : LongWord; 15 | 16 | AUX_ENABLES : LongWord; 17 | AUX_MU_IO_REG : LongWord; 18 | AUX_MU_IER_REG : LongWord; 19 | AUX_MU_IIR_REG : LongWord; 20 | AUX_MU_LCR_REG : LongWord; 21 | AUX_MU_MCR_REG : LongWord; 22 | AUX_MU_LSR_REG : LongWord; 23 | AUX_MU_MSR_REG : LongWord; 24 | AUX_MU_SCRATCH : LongWord; 25 | AUX_MU_CNTL_REG : LongWord; 26 | AUX_MU_STAT_REG : LongWord; 27 | AUX_MU_BAUD_REG : LongWord; 28 | 29 | ar, rb, rc: longword; 30 | i: longword; 31 | digits: pchar; 32 | pos: longword; 33 | 34 | procedure uartinit(); 35 | procedure uart_putc( c: longword ); 36 | procedure uart_puts( s: pchar ); 37 | 38 | procedure PUT32 ( address: longword; value:longword ); external 'PUT32'; 39 | function GET32 ( address: longword ): longword; external 'GET32'; 40 | Function makehex(val: longword): pchar; 41 | 42 | 43 | implementation 44 | 45 | procedure uartinit(); 46 | begin 47 | 48 | GPFSEL1 := $20200004; 49 | GPSET0 := $2020001C; 50 | GPCLR0 := $20200028; 51 | 52 | GPPUD := $20200094; 53 | GPPUDCLK0 := $20200098; 54 | 55 | AUX_ENABLES := $20215004; 56 | AUX_MU_IO_REG := $20215040; 57 | AUX_MU_IER_REG := $20215044; 58 | AUX_MU_IIR_REG := $20215048; 59 | AUX_MU_LCR_REG := $2021504C; 60 | AUX_MU_MCR_REG := $20215050; 61 | AUX_MU_LSR_REG := $20215054; 62 | AUX_MU_MSR_REG := $20215058; 63 | AUX_MU_SCRATCH := $2021505C; 64 | AUX_MU_CNTL_REG := $20215060; 65 | AUX_MU_STAT_REG := $20215064; 66 | AUX_MU_BAUD_REG := $20215068; 67 | 68 | PUT32(AUX_ENABLES,1); 69 | PUT32(AUX_MU_IER_REG,0); 70 | PUT32(AUX_MU_CNTL_REG,0); 71 | PUT32(AUX_MU_LCR_REG,3); 72 | PUT32(AUX_MU_MCR_REG,0); 73 | PUT32(AUX_MU_IER_REG,0); 74 | PUT32(AUX_MU_IIR_REG,$C6); 75 | PUT32(AUX_MU_BAUD_REG,270); 76 | 77 | ar := GET32(GPFSEL1); 78 | ar := ar and not (7 shl 12); 79 | ar := ar or (2 shl 12); 80 | PUT32(GPFSEL1,ar); 81 | 82 | PUT32(GPPUD,0); 83 | for ar:=0 to 149 do dummy(ar); 84 | PUT32(GPPUDCLK0,(1 shl 14)); 85 | for ar:=0 to 149 do dummy(ar); 86 | PUT32(GPPUDCLK0,0); 87 | PUT32(AUX_MU_CNTL_REG,2); 88 | 89 | end; 90 | 91 | procedure uart_putc( c: longword ); 92 | begin 93 | while(true) do 94 | begin 95 | if boolean(GET32(AUX_MU_LSR_REG) and $20)=true then break; 96 | end; 97 | PUT32(AUX_MU_IO_REG,longword(c)); 98 | end; 99 | 100 | Function makehex(val: longword): pchar; 101 | begin 102 | makehex:=''; 103 | pos:=0; 104 | 105 | rb:=32; 106 | while(true) do 107 | begin 108 | rb := rb - 4; 109 | rc := (val shr rb) and $F; 110 | if(rc>9) then rc := rc + $37 else rc := rc +$30; 111 | makehex[pos] := chr(rc); 112 | pos:=pos+1; 113 | if(rb=0) then break; 114 | end; 115 | makehex[pos] := chr($20); 116 | end; 117 | 118 | procedure uart_puts( s: pchar ); 119 | begin 120 | for i := 0 to strlen(s)-1 do 121 | begin 122 | uart_putc( longword(char(s[i])) ); 123 | end; 124 | end; 125 | 126 | end. 127 | -------------------------------------------------------------------------------- /examples/framebuf/src/fb.pas: -------------------------------------------------------------------------------- 1 | unit fb; 2 | 3 | interface 4 | 5 | uses gpio, uart, mailbox, font; 6 | 7 | type 8 | TRGB = packed record R, G, B: Byte; end; 9 | 10 | //bit = 0..1; 11 | 12 | TFlag = packed record 13 | case integer of 14 | 0: (fullByte : Byte); 15 | 1: (oneBit : bitpacked array[0..7] of boolean); //of bit 16 | end; 17 | 18 | 19 | (* 20 | {$ALIGN 16} 21 | tframebufferinfo = record 22 | width: longword; 23 | height: longword; 24 | vwidth: longword; 25 | vheight: longword; 26 | gpupitch: longword; 27 | bitdepth: longword; 28 | x: longword; 29 | y: longword; 30 | gpupointer: longword; 31 | gpusize: longword; 32 | end; 33 | *) 34 | 35 | // tfbi = array of longword; 36 | 37 | 38 | var 39 | // {$ALIGN 16} 40 | // framebufferinfo: ^tframebufferinfo; 41 | 42 | // fbi : tfbi; 43 | //fbi : ^tfbi; 44 | mailbuffer : ^tmb; 45 | framebufferbase: ^longword; 46 | fbb: longword; 47 | tempfb: ^trgb; 48 | // mailboxresult: longword; 49 | teller: longword; 50 | rmb: longword; 51 | color: trgb; 52 | red,green,blue: byte; 53 | c: longword; 54 | ar: longword; 55 | count: longword; 56 | pitch: longword; 57 | countx, county: longword; 58 | addr: longword; 59 | pixelwidth: longword; 60 | flag: TFlag; 61 | charpos: longword; 62 | row: longword; 63 | bit: longword; 64 | y: longword; 65 | 66 | //function InitialiseFrameBuffer(width: word; height: word; bitDepth: word): pointer; softfloat; external 'InitialiseFrameBuffer'; 67 | 68 | procedure framebufferinit(); 69 | procedure framebufferdrawchar(ac: longword; ax: longword; ay: longword); 70 | procedure framebufferdrawpixel(acolor: trgb; ax:longword; ay:longword); 71 | procedure framebufferfillscreen(); 72 | procedure fbdebug(); 73 | 74 | implementation 75 | 76 | procedure framebufferinit(); 77 | begin 78 | 79 | //okledoff(); 80 | 81 | //data structure 82 | (* 83 | framebufferinfo := pointer($1000); 84 | framebufferinfo^.width := 1024; 85 | framebufferinfo^.height := 768; 86 | framebufferinfo^.vwidth:= 1024; 87 | framebufferinfo^.vheight:= 768; 88 | framebufferinfo^.gpupitch:= 0; 89 | framebufferinfo^.bitdepth:= 16; 90 | framebufferinfo^.x := 0; 91 | framebufferinfo^.y := 0; 92 | framebufferinfo^.gpupointer:= 0; 93 | framebufferinfo^.gpusize:=0; 94 | *) 95 | (* 96 | fbi := pointer($1000); 97 | fbi^[0]:=1024; //width 98 | fbi^[1]:=768; //height 99 | fbi^[2]:=1024; //virtual width 100 | fbi^[3]:=768; //virtual height 101 | fbi^[4]:=0; //pitch 102 | fbi^[5]:=16; //depth 103 | fbi^[6]:=0; //xoffset 104 | fbi^[7]:=0; //yoffset 105 | fbi^[8]:=0; //address 106 | fbi^[9]:=0; //size 107 | fbi^[10]:=0; //something extra 108 | *) 109 | mailbuffer := pointer($1000); 110 | 111 | mailbuffer^[0] := 22*4; 112 | mailbuffer^[1] := 0; // Request 113 | 114 | mailbuffer^[2] := $00048003; // Tag id (set physical size) 115 | mailbuffer^[3] := 8; // Value buffer size (bytes) 116 | mailbuffer^[4] := 8; // Req. + value length (bytes) 117 | mailbuffer^[5] := 1024; // Horizontal resolution 118 | mailbuffer^[6] := 768; // Vertical resolution 119 | 120 | mailbuffer^[7] := $00048004; // Tag id (set virtual size) 121 | mailbuffer^[8] := 8; // Value buffer size (bytes) 122 | mailbuffer^[9] := 8; // Req. + value length (bytes) 123 | mailbuffer^[10] := 1024; // Horizontal resolution 124 | mailbuffer^[11] := 768; // Vertical resolution 125 | 126 | mailbuffer^[12] := $00048005; // Tag id (set depth) 127 | mailbuffer^[13] := 4; // Value buffer size (bytes) 128 | mailbuffer^[14] := 4; // Req. + value length (bytes) 129 | mailbuffer^[15] := 24; // 16 bpp 130 | 131 | mailbuffer^[16] := $00040001; // Tag id (allocate framebuffer) 132 | mailbuffer^[17] := 8; // Value buffer size (bytes) 133 | mailbuffer^[18] := 4; // Req. + value length (bytes) 134 | mailbuffer^[19] := 16; // Alignment = 16 135 | mailbuffer^[20] := 0; // Space for response 136 | 137 | mailbuffer^[21] := 0; // Terminating tag 138 | 139 | 140 | rmb:=0; 141 | mailboxwrite(8,$1000); //shr 4 142 | //okledoff(); 143 | rmb := mailboxread(8); 144 | 145 | 146 | 147 | count:=2; 148 | 149 | while(count<>c) do 150 | begin 151 | ar := mailbuffer^[count]; 152 | if(ar = $40001) then break; 153 | 154 | (* Skip to next tag 155 | * Advance count by 1 (tag) + 2 (buffer size/value size) 156 | * + specified buffer size 157 | *) 158 | count := count + 3+(mailbuffer^[count+1] shr 2); 159 | 160 | //if(count>c) 161 | // fb_fail(FBFAIL_INVALID_TAGS); 162 | end; 163 | 164 | //okledon(); 165 | 166 | 167 | //okledoff(); 168 | 169 | //okledoff(); 170 | //if rmb <> 1 then 171 | //begin 172 | // okledon(); 173 | //end; 174 | 175 | //okledoff(); 176 | //if fbi^[8] = 0 then 177 | //begin 178 | // okledon(); 179 | //end; 180 | 181 | //fbir := pointer(rmb); 182 | 183 | //if fbi[9] > 0 then 184 | //begin 185 | // okledon(); 186 | //end; 187 | 188 | //framebufferbase := pointer(framebufferinfo^.gpupointer); 189 | //framebufferbase := pointer(fbi^[8]); 190 | fbb := mailbuffer^[count+3]; 191 | framebufferbase := pointer(mailbuffer^[count+3]); 192 | 193 | mailbuffer^[0] := 7 * 4; // Total size 194 | mailbuffer^[1] := 0; // Request 195 | mailbuffer^[2] := $40008; // Display size 196 | mailbuffer^[3] := 4; // Buffer size 197 | mailbuffer^[4] := 0; // Request size 198 | mailbuffer^[5] := 0; // Space for pitch 199 | mailbuffer^[6] := 0; // End tag 200 | 201 | rmb:=0; 202 | mailboxwrite(8,$1000); //shr 4 203 | //okledoff(); 204 | rmb := mailboxread(8); 205 | 206 | pitch := mailbuffer^[5]; 207 | 208 | //framebufferbase := InitialiseFrameBuffer(1024,768,16); 209 | 210 | //if framebufferbase = nil then 211 | //begin 212 | // okledon(); 213 | //end; 214 | 215 | //now we have the framebuffer address in gpupointer; 216 | 217 | 218 | 219 | end; 220 | 221 | procedure fbdebug(); 222 | begin 223 | uart_puts( ' fddebug ' ); 224 | //uart_puts( pchar(makehex( mailbuffer^[1] )) ); 225 | //uart_puts(' | '); 226 | //uart_puts( pchar(makehex( mailbuffer^[count+0] )) ); 227 | //uart_puts( pchar(makehex( mailbuffer^[count+1] )) ); 228 | //uart_puts( pchar(makehex( mailbuffer^[count+2] )) ); 229 | //uart_puts( pchar(makehex( mailbuffer^[count+3] )) ); 230 | //uart_puts( pchar(makehex( mailbuffer^[count+4] )) ); 231 | uart_puts( pchar(makehex( mailbuffer^[5] )) ); 232 | //uart_puts( pchar(makehex( mailbuffer^[count+6] )) ); 233 | (* 234 | if ($1000 and 15) <> 0 then 235 | begin 236 | uart_puts('not 16 byte algined'); 237 | end; 238 | *) 239 | uart_puts( ' end fddebug ' ); 240 | 241 | flag.fullbyte := $1; 242 | flag.onebit[0] := true; 243 | 244 | end; 245 | 246 | procedure framebufferdrawchar(ac: longword; ax: longword; ay: longword); 247 | begin 248 | pos := ac * 16; 249 | row := 0; 250 | y:=ay; 251 | for row:=0 to 15 do 252 | begin 253 | bit:=0; 254 | for bit:=0 to 7 do 255 | begin 256 | if (tflag(defaultfont[pos+row]).onebit[bit]=true) then 257 | begin 258 | framebufferdrawpixel(color,ax+bit,y); 259 | end; 260 | //framebufferdrawpixel(color,ax+bit,y); 261 | end; 262 | y:=y+1; 263 | end; 264 | 265 | end; 266 | 267 | procedure framebufferdrawpixel(acolor: trgb; ax:longword; ay:longword); 268 | begin 269 | addr:=(ax + (ay * 1024)) * 3; // 1024=width 3=pixelwidth in bytes (24bit) 270 | tempfb := pointer(fbb + addr); 271 | tempfb^ := acolor; 272 | end; 273 | 274 | procedure framebufferfillscreen(); 275 | begin 276 | //red:=$FF; 277 | //green:=$00; 278 | //blue:=$00; 279 | //color := (blue shr 8) shl 8 + (green shr 8) shl 8 + (red shr 8) shl 8; 280 | color.r := $00; 281 | color.g := $FF; 282 | color.b := $00; 283 | 284 | pixelwidth:=$1; 285 | addr:=0; 286 | //tempfb := framebufferbase; 287 | county:=0; 288 | for county := 0 to (768)-1 do 289 | begin 290 | countx:=0; 291 | for countx := 0 to (1024)-1 do 292 | begin 293 | //tempfb := pointer(fbb + addr); 294 | //tempfb^ := color; 295 | //addr:=addr+3; 296 | framebufferdrawpixel(color,countx,county); 297 | 298 | end; 299 | 300 | end; 301 | 302 | color.r := $FF; 303 | color.g := $00; 304 | color.b := $00; 305 | //framebufferdrawchar(longword(char('a')), 0, 0); 306 | framebufferdrawchar(97, 16, 16); 307 | 308 | end; 309 | 310 | 311 | 312 | end. 313 | -------------------------------------------------------------------------------- /examples/framebuf/src/font.pas: -------------------------------------------------------------------------------- 1 | Unit font; 2 | 3 | Interface 4 | 5 | 6 | Const 7 | defaultfont : Array[0..2047] of byte = ( 8 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39 | 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 0, 8, 8, 0, 0, 0, 0, 40 | 0, 0, 0, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41 | 0, 72, 72,104,254, 36, 36,127, 20, 18, 18, 0, 0, 0, 0, 0, 0, 42 | 0, 16,124,146, 18, 28,112,144,146,124, 16, 16, 0, 0, 0, 0, 0, 43 | 6, 9, 9, 70, 56,102,144,144, 96, 0, 0, 0, 0, 0, 0, 0, 56, 44 | 4, 4, 12,146,178,162, 70,188, 0, 0, 0, 0, 0, 0, 0, 8, 8, 45 | 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 16, 16, 8, 8, 46 | 8, 8, 8, 8, 16, 16, 32, 0, 0, 0, 0, 12, 8, 8, 16, 16, 16, 47 | 16, 16, 16, 8, 8, 12, 0, 0, 0, 0, 0, 0, 16,146,124, 56,214, 48 | 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,127, 8, 49 | 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50 | 24, 24, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 51 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 52 | 0, 0, 0, 0, 0, 0, 0, 64, 32, 32, 16, 16, 24, 8, 8, 4, 4, 53 | 2, 0, 0, 0, 0, 0, 56, 68,130,130,146,130,130, 68, 56, 0, 0, 54 | 0, 0, 0, 0, 0, 28, 16, 16, 16, 16, 16, 16, 16,124, 0, 0, 0, 55 | 0, 0, 0, 0,124,194,128,128, 64, 48, 24, 4,254, 0, 0, 0, 0, 56 | 0, 0, 0,124,130,128,192, 56,192,128,194,124, 0, 0, 0, 0, 0, 57 | 0, 0, 96, 80, 88, 72, 68, 66,254, 64, 64, 0, 0, 0, 0, 0, 0, 58 | 0,126, 2, 2, 62,192,128,128,194, 60, 0, 0, 0, 0, 0, 0, 0, 59 | 120,132, 2,122,198,130,130,196,120, 0, 0, 0, 0, 0, 0, 0,254, 60 | 64, 64, 32, 32, 16, 24, 8, 4, 0, 0, 0, 0, 0, 0, 0,124,130, 61 | 130,130,124,130,130,134,124, 0, 0, 0, 0, 0, 0, 0, 60, 70,130, 62 | 130,198,188,128, 66, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 63 | 0, 0, 0, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 0, 64 | 0, 0, 24, 24, 8, 4, 0, 0, 0, 0, 0, 0, 0,128,112, 14, 14, 65 | 112,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,254, 0, 0,254, 66 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 28,224,224, 28, 2, 67 | 0, 0, 0, 0, 0, 0, 0, 0, 28, 34, 32, 16, 8, 8, 0, 8, 8, 68 | 0, 0, 0, 0, 0, 0, 0,120,204,132,226,146,146,146,226, 4, 12, 69 | 120, 0, 0, 0, 0, 0, 16, 40, 40, 40, 68, 68,124,198,130, 0, 0, 70 | 0, 0, 0, 0, 0,126,130,130,130,126,130,130,130,126, 0, 0, 0, 71 | 0, 0, 0, 0,120,132, 2, 2, 2, 2, 2,132,120, 0, 0, 0, 0, 72 | 0, 0, 0, 62, 66,130,130,130,130,130, 66, 62, 0, 0, 0, 0, 0, 73 | 0, 0,254, 2, 2, 2,254, 2, 2, 2,254, 0, 0, 0, 0, 0, 0, 74 | 0,254, 2, 2, 2,254, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 75 | 120,132, 2, 2,194,130,130,132,120, 0, 0, 0, 0, 0, 0, 0,130, 76 | 130,130,130,254,130,130,130,130, 0, 0, 0, 0, 0, 0, 0, 62, 8, 77 | 8, 8, 8, 8, 8, 8, 62, 0, 0, 0, 0, 0, 0, 0, 56, 32, 32, 78 | 32, 32, 32, 32, 34, 28, 0, 0, 0, 0, 0, 0, 0, 66, 34, 18, 10, 79 | 14, 18, 34, 34, 66, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 80 | 2, 2, 2,254, 0, 0, 0, 0, 0, 0, 0,198,198,170,170,170,146, 81 | 130,130,130, 0, 0, 0, 0, 0, 0, 0,134,134,138,138,146,162,162, 82 | 194,194, 0, 0, 0, 0, 0, 0, 0, 56, 68,130,130,130,130,130, 68, 83 | 56, 0, 0, 0, 0, 0, 0, 0,126,194,130,130,194,126, 2, 2, 2, 84 | 0, 0, 0, 0, 0, 0, 0, 56, 68,130,130,130,130,130, 68,120, 96, 85 | 64, 0, 0, 0, 0, 0,126,194,130,130,126, 66,130,130, 2, 0, 0, 86 | 0, 0, 0, 0, 0,124,134, 2, 6,124,192,128,194,125, 0, 0, 0, 87 | 0, 0, 0, 0,127, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 88 | 0, 0, 0,130,130,130,130,130,130,130,130,124, 0, 0, 0, 0, 0, 89 | 0, 0,130,198, 68, 68, 68, 40, 40, 40, 16, 0, 0, 0, 0, 0, 0, 90 | 0,129,129,129, 90, 90, 90,102,102,102, 0, 0, 0, 0, 0, 0, 0, 91 | 198, 68, 40, 56, 16, 40,108, 68,130, 0, 0, 0, 0, 0, 0, 0, 65, 92 | 34, 20, 20, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0,254,192, 93 | 96, 32, 16, 8, 12, 6,254, 0, 0, 0, 0, 0, 56, 8, 8, 8, 8, 94 | 8, 8, 8, 8, 8, 8, 56, 0, 0, 0, 0, 0, 0, 2, 4, 4, 8, 95 | 8, 24, 16, 16, 32, 32, 64, 0, 0, 0, 28, 16, 16, 16, 16, 16, 16, 96 | 16, 16, 16, 16, 28, 0, 0, 0, 0, 0, 0, 8, 20, 34, 99, 0, 0, 97 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98 | 0, 0, 0, 0,127, 0, 0, 0, 8, 16, 0, 0, 0, 0, 0, 0, 0, 99 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 68, 64,124, 66, 98, 92, 100 | 0, 0, 0, 0, 0, 2, 2, 2, 2, 62,102, 66, 66, 66,102, 62, 0, 101 | 0, 0, 0, 0, 0, 0, 0, 0, 56, 68, 2, 2, 2, 68, 56, 0, 0, 102 | 0, 0, 0, 64, 64, 64, 64,124,102, 66, 66, 66,102,124, 0, 0, 0, 103 | 0, 0, 0, 0, 0, 0, 60,102, 66,126, 2, 70, 60, 0, 0, 0, 0, 104 | 0, 48, 8, 8, 8, 62, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 105 | 0, 0, 0, 0,124,102, 66, 66, 66,102, 92, 64, 68, 56, 0, 0, 2, 106 | 2, 2, 2, 58, 70, 66, 66, 66, 66, 66, 0, 0, 0, 0, 0, 8, 0, 107 | 0, 0, 14, 8, 8, 8, 8, 8, 62, 0, 0, 0, 0, 0, 16, 0, 0, 108 | 0, 28, 16, 16, 16, 16, 16, 16, 16, 16, 14, 0, 0, 2, 2, 2, 2, 109 | 34, 18, 10, 14, 18, 34, 66, 0, 0, 0, 0, 0, 14, 8, 8, 8, 8, 110 | 8, 8, 8, 8, 8,112, 0, 0, 0, 0, 0, 0, 0, 0, 0,254,146, 111 | 146,146,146,146,146, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 70, 66, 112 | 66, 66, 66, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,102, 66, 66, 113 | 66,102, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62,102, 66, 66, 66, 114 | 102, 62, 2, 2, 2, 0, 0, 0, 0, 0, 0,124,102, 66, 66, 66,102, 115 | 92, 64, 64, 64, 0, 0, 0, 0, 0, 0, 60, 76, 4, 4, 4, 4, 4, 116 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 66, 2, 60, 64, 66, 60, 0, 117 | 0, 0, 0, 0, 0, 0, 8, 8,126, 8, 8, 8, 8, 8,112, 0, 0, 118 | 0, 0, 0, 0, 0, 0, 0, 66, 66, 66, 66, 66, 98, 92, 0, 0, 0, 119 | 0, 0, 0, 0, 0, 0, 66,102, 36, 36, 60, 24, 24, 0, 0, 0, 0, 120 | 0, 0, 0, 0, 0,129,129, 90, 90, 90, 36, 36, 0, 0, 0, 0, 0, 121 | 0, 0, 0, 0,102, 36, 24, 24, 24, 36,102, 0, 0, 0, 0, 0, 0, 122 | 0, 0, 0, 66, 68, 36, 36, 40, 24, 16, 16, 8, 12, 0, 0, 0, 0, 123 | 0, 0,126, 64, 32, 24, 4, 2,126, 0, 0, 0, 0, 0, 56, 8, 8, 124 | 8, 8, 6, 8, 8, 8, 8, 8, 48, 0, 0, 0, 0, 8, 8, 8, 8, 125 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 14, 8, 8, 8, 8, 126 | 48, 8, 8, 8, 8, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127 | 156, 98, 0, 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,255,255, 128 | 255,255,255,255,255,255,255,255); 129 | 130 | Implementation 131 | 132 | end. 133 | --------------------------------------------------------------------------------