From 7274dccbe7047dcd8e6409d19f3e5d944dd54e5b Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 13 Nov 2019 20:38:06 -0500 Subject: [PATCH] Move ASCII consts to ascii.h And made them shorter in name. The new ascii.h file allow reuse in userspace code. --- apps/zasm/glue.asm | 1 + apps/zasm/tok.asm | 6 +++--- doc/glue-code.md | 1 + kernel/ascii.h | 4 ++++ kernel/core.asm | 22 ++++++---------------- kernel/shell.asm | 2 +- kernel/sms/pad.asm | 4 ++-- kernel/sms/vdp.asm | 6 +++--- kernel/stdio.asm | 18 +++++++++--------- kernel/ti/lcd.asm | 4 ++-- recipes/rc2014/eeprom/glue.asm | 1 + recipes/rc2014/glue.asm | 1 + recipes/rc2014/ps2/glue.asm | 1 + recipes/rc2014/sdcard/glue.asm | 1 + recipes/rc2014/zasm/glue.asm | 1 + recipes/sms/glue.asm | 1 + recipes/sms/kbd/glue.asm | 1 + recipes/sms/romasm/glue.asm | 1 + recipes/ti84/glue.asm | 1 + tools/emul/shell/shell_.asm | 1 + tools/emul/zasm/glue.asm | 1 + 21 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 kernel/ascii.h diff --git a/apps/zasm/glue.asm b/apps/zasm/glue.asm index f832ac5..92391dd 100644 --- a/apps/zasm/glue.asm +++ b/apps/zasm/glue.asm @@ -68,6 +68,7 @@ ; ****** .inc "err.h" +.inc "ascii.h" .org USER_CODE jp zasmMain diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index 5799a73..a7b8750 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -22,14 +22,14 @@ isLineEndOrComment: isLineEnd: or a ; same as cp 0 ret z - cp 0x0d + cp CR ret z - cp 0x0a + cp LF ret z cp '\' ret -; Sets Z is A is ' ' '\t' or ',' +; Sets Z is A is ' ' '\t' isSep: cp ' ' ret z diff --git a/doc/glue-code.md b/doc/glue-code.md index 1533adf..157fb0b 100644 --- a/doc/glue-code.md +++ b/doc/glue-code.md @@ -19,6 +19,7 @@ look like: jp aciaInt .inc "err.h" + .inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/kernel/ascii.h b/kernel/ascii.h new file mode 100644 index 0000000..1febc86 --- /dev/null +++ b/kernel/ascii.h @@ -0,0 +1,4 @@ +.equ BS 0x08 +.equ CR 0x0d +.equ LF 0x0a +.equ DEL 0x7f diff --git a/kernel/core.asm b/kernel/core.asm index be41e97..10de0ca 100644 --- a/kernel/core.asm +++ b/kernel/core.asm @@ -3,16 +3,6 @@ ; Routines used by pretty much all parts. You will want to include it first ; in your glue file. -; *** CONSTS *** -.equ ASCII_BS 0x08 -.equ ASCII_CR 0x0d -.equ ASCII_LF 0x0a -.equ ASCII_DEL 0x7f - -; *** DATA *** -; Useful data to point to, when a pointer is needed. -P_NULL: .db 0 - ; *** REGISTER FIDDLING *** ; add the value of A into DE @@ -27,7 +17,7 @@ addDE: noop: ; piggy backing on the first "ret" we have ret -; copy (HL) into DE, then exchange the two, utilising the optimised HL instructions. +; copy (HL) into DE, then exchange the two, utilising the optimised HL instructions. ; ld must be done little endian, so least significant byte first. intoHL: push de @@ -86,7 +76,7 @@ cpHLDE: ; Write the contents of HL in (DE) ; de and hl are preserved, so no pushing/popping necessary writeHLinDE: - ex de, hl + ex de, hl ld (hl), e inc hl ld (hl), d @@ -112,8 +102,8 @@ callIY: jp (iy) ; Ensures that Z is unset (more complicated than it sounds...) -; There are often better inline alternatives, either replacing rets with -; appropriate jmps, or if an 8 bit register is known to not be 0, an inc +; There are often better inline alternatives, either replacing rets with +; appropriate jmps, or if an 8 bit register is known to not be 0, an inc ; then a dec. If a is nonzero, 'or a' is optimal. unsetZ: or a ;if a nonzero, Z reset @@ -177,9 +167,9 @@ fmtHex: ; it adds 6 to that nibble, carrying to the next nibble and bringing the ; value back between 0-9. This gives us 6 of that 7 we needed to add, so ; then we just condtionally set the carry and add that carry, along with - ; a number that maps 0 to '0'. We also need the upper nibble to be a + ; a number that maps 0 to '0'. We also need the upper nibble to be a ; set value, and have the N, C and H flags clear. - or 0xf0 + or 0xf0 daa ; now a =0x50 + the original value + 0x06 if >= 0xfa add a, 0xa0 ; cause a carry for the values that were >=0x0a adc a, 0x40 diff --git a/kernel/shell.asm b/kernel/shell.asm index 60d8729..77ae1c9 100644 --- a/kernel/shell.asm +++ b/kernel/shell.asm @@ -66,7 +66,7 @@ shellInit: jp printstr .welcome: - .db "Collapse OS", ASCII_CR, ASCII_LF, "> ", 0 + .db "Collapse OS", CR, LF, "> ", 0 ; Inifite loop that processes input. Because it's infinite, you should jump ; to it rather than call it. Saves two precious bytes in the stack. diff --git a/kernel/sms/pad.asm b/kernel/sms/pad.asm index b004f9d..308e0b9 100644 --- a/kernel/sms/pad.asm +++ b/kernel/sms/pad.asm @@ -185,7 +185,7 @@ padGetC: call vdpSpitC jp padGetC .return: - ld a, ASCII_LF + ld a, LF ld (PAD_NEXTCHR), a ; continue to .advance .advance: @@ -193,7 +193,7 @@ padGetC: ; Z was already set from previous BIT instruction ret .backspace: - ld a, ASCII_BS + ld a, BS ; Z was already set from previous BIT instruction ret .nextchr: diff --git a/kernel/sms/vdp.asm b/kernel/sms/vdp.asm index ce6d271..f8e0a45 100644 --- a/kernel/sms/vdp.asm +++ b/kernel/sms/vdp.asm @@ -119,11 +119,11 @@ vdpPutC: ; 6 low bits contain our row*2 (each tile is 2 bytes wide) and high ; 2 bits are the two low bits of our line ; special case: line feed, carriage return, back space - cp ASCII_LF + cp LF jr z, vdpLF - cp ASCII_CR + cp CR jr z, vdpCR - cp ASCII_BS + cp BS jr z, vdpBS push af diff --git a/kernel/stdio.asm b/kernel/stdio.asm index a58b8ee..a352b75 100644 --- a/kernel/stdio.asm +++ b/kernel/stdio.asm @@ -23,7 +23,7 @@ ; *** Defines *** ; STDIO_GETC: address of a GetC routine ; STDIO_PUTC: address of a PutC routine -; +; ; *** Consts *** ; Size of the readline buffer. If a typed line reaches this size, the line is ; flushed immediately (same as pressing return). @@ -81,9 +81,9 @@ printnstr: printcrlf: push af - ld a, ASCII_CR + ld a, CR call STDIO_PUTC - ld a, ASCII_LF + ld a, LF call STDIO_PUTC pop af ret @@ -124,13 +124,13 @@ stdioReadLine: ; Let's wait until something is typed. call STDIO_GETC ; got it. Now, is it a CR or LF? - cp ASCII_CR + cp CR jr z, .complete ; char is CR? buffer complete! - cp ASCII_LF + cp LF jr z, .complete - cp ASCII_DEL + cp DEL jr z, .delchr - cp ASCII_BS + cp BS jr z, .delchr ; Echo the received character right away so that we see what we type @@ -161,10 +161,10 @@ stdioReadLine: inc b ; Char deleted in buffer, now send BS + space + BS for the terminal ; to clear its previous char - ld a, ASCII_BS + ld a, BS call STDIO_PUTC ld a, ' ' call STDIO_PUTC - ld a, ASCII_BS + ld a, BS call STDIO_PUTC jr .loop diff --git a/kernel/ti/lcd.asm b/kernel/ti/lcd.asm index e501b83..3973b45 100644 --- a/kernel/ti/lcd.asm +++ b/kernel/ti/lcd.asm @@ -329,9 +329,9 @@ lcdClrScr: ret lcdPutC: - cp ASCII_LF + cp LF jp z, lcdLinefeed - cp ASCII_BS + cp BS jr z, .bs push hl call fntGet diff --git a/recipes/rc2014/eeprom/glue.asm b/recipes/rc2014/eeprom/glue.asm index c375413..9cd1e7f 100644 --- a/recipes/rc2014/eeprom/glue.asm +++ b/recipes/rc2014/eeprom/glue.asm @@ -12,6 +12,7 @@ jp init jp aciaInt .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/recipes/rc2014/glue.asm b/recipes/rc2014/glue.asm index 9ded2da..55d94d8 100644 --- a/recipes/rc2014/glue.asm +++ b/recipes/rc2014/glue.asm @@ -12,6 +12,7 @@ jp init jp aciaInt .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/recipes/rc2014/ps2/glue.asm b/recipes/rc2014/ps2/glue.asm index 6096e6a..8e80268 100644 --- a/recipes/rc2014/ps2/glue.asm +++ b/recipes/rc2014/ps2/glue.asm @@ -7,6 +7,7 @@ jp init .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index 474de9c..fbf8b95 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -21,6 +21,7 @@ jp sdcSendRecv jp aciaInt .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/recipes/rc2014/zasm/glue.asm b/recipes/rc2014/zasm/glue.asm index a93ef6b..b1fbb99 100644 --- a/recipes/rc2014/zasm/glue.asm +++ b/recipes/rc2014/zasm/glue.asm @@ -47,6 +47,7 @@ jp aciaInt jp blkGetB .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" .equ ACIA_RAMSTART RAMSTART diff --git a/recipes/sms/glue.asm b/recipes/sms/glue.asm index c2ab816..497408d 100644 --- a/recipes/sms/glue.asm +++ b/recipes/sms/glue.asm @@ -9,6 +9,7 @@ retn .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" diff --git a/recipes/sms/kbd/glue.asm b/recipes/sms/kbd/glue.asm index 87723a6..fce14d7 100644 --- a/recipes/sms/kbd/glue.asm +++ b/recipes/sms/kbd/glue.asm @@ -9,6 +9,7 @@ retn .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" diff --git a/recipes/sms/romasm/glue.asm b/recipes/sms/romasm/glue.asm index 6daf3a1..03483eb 100644 --- a/recipes/sms/romasm/glue.asm +++ b/recipes/sms/romasm/glue.asm @@ -40,6 +40,7 @@ retn .inc "err.h" +.inc "ascii.h" .inc "core.asm" .inc "parse.asm" diff --git a/recipes/ti84/glue.asm b/recipes/ti84/glue.asm index 301d60a..1f9202f 100644 --- a/recipes/ti84/glue.asm +++ b/recipes/ti84/glue.asm @@ -22,6 +22,7 @@ .fill 0x64-$ .inc "err.h" +.inc "ascii.h" .inc "core.asm" .equ FNT_WIDTH 3 .equ FNT_HEIGHT 5 diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index cda6357..1881c71 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -42,6 +42,7 @@ .inc "core.asm" .inc "err.h" +.inc "ascii.h" .inc "parse.asm" .equ BLOCKDEV_RAMSTART RAMSTART diff --git a/tools/emul/zasm/glue.asm b/tools/emul/zasm/glue.asm index 3ccec75..7f60df7 100644 --- a/tools/emul/zasm/glue.asm +++ b/tools/emul/zasm/glue.asm @@ -33,6 +33,7 @@ jp printstr .inc "core.asm" .inc "err.h" +.inc "ascii.h" .inc "parse.asm" .equ BLOCKDEV_RAMSTART RAMSTART .equ BLOCKDEV_COUNT 3