123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- ## Copyright (C) 2016 Jeremiah Orians
- ## This file is part of stage0.
- ##
- ## stage0 is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- ##
- ## stage0 is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ##
- ## You should have received a copy of the GNU General Public License
- ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
- # :start 0
- E0002D2B0001 # LOADUI R11 1 ; Our toggle
- E0002D2D0600 # LOADUI R13 0x600 ; Where we are starting our Stack
- # ;; R14 will be storing our condition
- 0D00002F # FALSE R15 ; Our holder
- # ;; Prep TAPE_01
- E0002D201100 # LOADUI R0 0x1100
- 42100001 # FOPEN_WRITE
- # ;; Prep TAPE_02
- E0002D201101 # LOADUI R0 0x1101
- 42100001 # FOPEN_WRITE
- # :loop 24
- E0002D210000 # LOADUI R1 0 ; Read from tty
- 42100100 # FGETC ; Read a Char
- E000A030000d # CMPSKIPI.NE R0 13 ; Replace all CR
- E0002D20000a # LOADUI R0 10 ; WIth LF
- 42100200 # FPUTC ; Display the Char to User
- # ;; Check for Ctrl-D
- E000A0300004 # CMPSKIPI.NE R0 4
- 3C000112 # JUMP @finish
- # ;; Check for EOF
- E0002CC0010c # JUMP.NP R0 @finish
- # ;; Write out unprocessed byte
- E0002D211101 # LOADUI R1 0x1101 ; Write to TAPE_02
- 42100200 # FPUTC ; Print the Char
- # ;; Convert byte to nybble
- E0002D0D003e # CALLI R13 @hex ; Convert it
- # ;; Get another byte if nonhex
- E0002CC0ffc0 # JUMP.NP R0 @loop ; Don't use nonhex chars
- # ;; Deal with the case of second nybble
- E0002C9B000e # JUMP.Z R11 @second_nybble ; Jump if toggled
- # ;; Process first byte of pair
- E100B0F0000f # ANDI R15 R0 0x0F ; Store First nibble
- 0D00002B # FALSE R11 ; Flip the toggle
- 3C00ffac # JUMP @loop
- # ;; Combined second nybble in pair with first
- # :second_nybble 78
- E0002D5F0004 # SL0I R15 4 ; Shift our first nibble
- E100B000000f # ANDI R0 R0 0x0F ; Mask out top
- 0500000F # ADD R0 R0 R15 ; Combine nibbles
- # ;; Writeout and prepare for next cycle
- E0002D1B0001 # LOADI R11 1 ; Flip the toggle
- E0002D211100 # LOADUI R1 0x1100 ; Write the combined byte
- 42100200 # FPUTC ; To TAPE_01
- 3C00ff88 # JUMP @loop ; Try to get more bytes
- # :hex 9c
- # ;; Deal with line comments starting with #
- E1001FE00023 # CMPUI R14 R0 35
- E0002C5E007e # JUMP.E R14 @ascii_comment
- # ;; Deal with line comments starting with ;
- E1001FE0003b # CMPUI R14 R0 59
- E0002C5E0072 # JUMP.E R14 @ascii_comment
- # ;; Deal with all ascii less than '0'
- E1001FE00030 # CMPUI R14 R0 48
- E0002C8E005e # JUMP.L R14 @ascii_other
- # ;; Deal with '0'-'9'
- E1001FE00039 # CMPUI R14 R0 57
- E0002C7E0034 # JUMP.LE R14 @ascii_num
- # ;; Deal with all ascii less than 'A'
- E1001FE00041 # CMPUI R14 R0 65
- E0002C8E0046 # JUMP.L R14 @ascii_other
- # ;; Deal with 'A'-'F'
- E1001FE00046 # CMPUI R14 R0 70
- E0002C7E0030 # JUMP.LE R14 @ascii_high
- # ;; Deal with all ascii less than 'a'
- E1001FE00061 # CMPUI R14 R0 97
- E0002C8E002e # JUMP.L R14 @ascii_other
- # ;; Deal with 'a'-'f'
- E1001FE00066 # CMPUI R14 R0 102
- E0002C7E000e # JUMP.LE R14 @ascii_low
- # ;; Ignore the rest
- 3C00001e # JUMP @ascii_other
- # :ascii_num 100
- E10011000030 # SUBUI R0 R0 48
- 0D01001D # RET R13
- # :ascii_low 10a
- E10011000057 # SUBUI R0 R0 87
- 0D01001D # RET R13
- # :ascii_high 114
- E10011000037 # SUBUI R0 R0 55
- 0D01001D # RET R13
- # :ascii_other 11e
- 0D000030 # TRUE R0
- 0D01001D # RET R13
- # :ascii_comment 126
- E0002D210000 # LOADUI R1 0 ; Read from tty
- 42100100 # FGETC ; Read another char
- E000A030000d # CMPSKIPI.NE R0 13 ; Replace all CR
- E0002D20000a # LOADUI R0 10 ; WIth LF
- 42100200 # FPUTC ; Let the user see it
- E1001FE0000a # CMPUI R14 R0 10 ; Stop at the end of line
- E0002D211101 # LOADUI R1 0x1101 ; Write to TAPE_02
- 42100200 # FPUTC ; The char we just read
- E0002C6Effd0 # JUMP.NE R14 @ascii_comment ; Otherwise keep looping
- 3C00ffc4 # JUMP @ascii_other
- # :finish 15a
- E0002D201100 # LOADUI R0 0x1100 ; Close TAPE_01
- 42100002 # FCLOSE
- E0002D201101 # LOADUI R0 0x1101 ; Close TAPE_02
- 42100002 # FCLOSE
- FFFFFFFF # HALT
|