- .begin
- ! Constants
- BASE .equ 0x3fffc0 ! Starting point of the memory mapped region
- CONSOLE .equ 0x0 ! 0xffff0000 Console Data Port
- CONSOLE_STATUS .equ 0x4 ! 0xffff0004 Console Status Port (-0x80 = Not Ready)
- KEYBOARD .equ 0x8 ! 0xffff0008 Keyboard in port
- KEYBOARD_STATUS .equ 0xc ! 0xffff000c Keyboard status port
- ! Push the contents of a register onto the stack.
- .macro PUSH arg1
- st arg1, %r14 ! Store the value
- sub %r14, 4, %r14 ! Decrement the stack pointer
- .endmacro
- ! Pop whatever is on the top of the stack and put it in arg1
- .macro POP arg1
- add %r14, 4, %r14 ! Incremement the stack
- ld %r14, arg1 ! Get the value
- st %r0, %r14 ! Clear it out - makes it easier to debg
- .endmacro
- .macro RETURN
- jmpl %r15 + 4, %r0
- .endmacro
- !-------------------------------------------------------
- ! Start
- !-------------------------------------------------------
- .org 2048
- ld [SP], %r14 ! Load the address of our string onto the stack
- MAIN_LOOP:
- call READ_CHAR
- POP %r1
- subcc %r1, 0x1B, %r0 ! Compare with ESC
- be QUIT
- PUSH %r1
- call PRINT_CHAR
- ba MAIN_LOOP
- QUIT:
- halt
- !-------------------------------------------------------
- !-------------------------------------------------------
- ! READ_CHAR FUNCTION
- ! Reads a single char from the input console
- ! RETURN = Char Found
- !-------------------------------------------------------
- READ_CHAR:
- ! We never call out, so %r15 is safe- don't need to store it
- add %r0, %r0, %r4 ! %r4 Holds the base address
- sethi BASE, %r4 !
- READ_CHAR_WAIT:
- ldub [%r4 + KEYBOARD_STATUS], %r1 ! Get the status
- andcc %r1, 0x80, %r1 ! Add 0x80 - if we're ready, this is not zero
- be READ_CHAR_WAIT ! Loop
- ldub [%r4 + KEYBOARD], %r3 ! Get the char
- PUSH %r3 ! Push the result on the stack and...
- RETURN ! Return
- !-------------------------------------------------------
- !-------------------------------------------------------
- ! PRINT_CHAR FUNCTION
- ! Prints a single char to the output console
- ! ARG1 = Char to print
- ! RETURN = Nothing
- !-------------------------------------------------------
- PRINT_CHAR:
- POP %r1 ! Grab the char to print
- ! We never call out, so we can assume %r15 stays put
- add %r0, %r0, %r4 ! %r4 Holds the base address
- sethi BASE, %r4 !
- PRINT_CHAR_WAIT: ! We have to wait for the console to be ready!
- ldub [%r4+ CONSOLE_STATUS], %r5
- ! Load the console status (as an unsigned byte) into %r5
- andcc %r5, 0x80, %r5 ! -0x80 = no console not ready, so add 0x80 to the value and compare against zero
- be PRINT_CHAR_WAIT ! Loop while we're not ready
- stb %r1, [%r4 + CONSOLE] ! We're ready - put the char to print into the console memory location
- RETURN
- !-------------------------------------------------------
- SP: 0x7FFFFFFC
- .end
typing
By: microhaxo | Date: Jul 4 2009 00:22 | Format: None | Expires: never | Size: 2.86 KB | Hits: 961
Latest pastes
51 minutes ago
10 hours ago
1 days ago
2 days ago
2 days ago