From 5283066c556e1e4e47e2cb8ec7833deb6ca3ec63 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Oct 2015 08:58:16 -0400 Subject: [PATCH 1/4] Add 3x3 font --- src/01/font.asm | 474 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 474 insertions(+) diff --git a/src/01/font.asm b/src/01/font.asm index 668fd6b..1e7a002 100644 --- a/src/01/font.asm +++ b/src/01/font.asm @@ -1767,3 +1767,477 @@ kernel_font: .db 0b10100000 .db 0b01000000 .db 0b10000000 + +font_3x3: + ; [space] + .db 0, 0, 0 + + ; ! + .db 0b11100000 + .db 0b11100000 + .db 0b01000000 + + ; " + .db 0b10100000 + .db 0b00000000 + .db 0b00000000 + + ; # + .db 0b11100000 + .db 0b11100000 + .db 0b11100000 + + ; $ + .db 0b01100000 + .db 0b00000000 + .db 0b11000000 + + ; % + .db 0b00100000 + .db 0b01000000 + .db 0b10100000 + + ; & + .db 0b01100000 + .db 0b01000000 + .db 0b11100000 + + ; ' + .db 0b01000000 + .db 0b00000000 + .db 0b00000000 + + ; ( + .db 0b01000000 + .db 0b10000000 + .db 0b01000000 + + ; ) + .db 0b01000000 + .db 0b00100000 + .db 0b01000000 + + ; * + .db 0b01100000 + .db 0b00000000 + .db 0b00000000 + + ; + + .db 0b01000000 + .db 0b11100000 + .db 0b01000000 + + ; , + .db 0b00000000 + .db 0b00000000 + .db 0b01100000 + + ; - + .db 0b00000000 + .db 0b00000000 + .db 0b11100000 + + ; . + .db 0b00000000 + .db 0b00000000 + .db 0b01000000 + + ; / + .db 0b00100000 + .db 0b01000000 + .db 0b10000000 + + ; 0 + .db 0b11100000 + .db 0b10100000 + .db 0b11100000 + + ; 1 + .db 0b11000000 + .db 0b01000000 + .db 0b11100000 + + ; 2 + .db 0b01100000 + .db 0b11000000 + .db 0b11100000 + + ; 3 + .db 0b11000000 + .db 0b01100000 + .db 0b11000000 + + ; 4 + .db 0b10100000 + .db 0b11100000 + .db 0b00100000 + + ; 5 + .db 0b11000000 + .db 0b01100000 + .db 0b11100000 + + ; 6 + .db 0b10000000 + .db 0b11100000 + .db 0b11100000 + + ; 7 + .db 0b11100000 + .db 0b00100000 + .db 0b00100000 + + ; 8 + .db 0b01100000 + .db 0b11100000 + .db 0b11000000 + + ; 9 + .db 0b11100000 + .db 0b11100000 + .db 0b00100000 + + ; : + .db 0b01000000 + .db 0b00000000 + .db 0b01000000 + + ; ; + .db 0b01000000 + .db 0b00000000 + .db 0b11000000 + + ; < + .db 0b01100000 + .db 0b10000000 + .db 0b01100000 + + ; = + .db 0b11100000 + .db 0b00000000 + .db 0b11100000 + + ; > + .db 0b01100000 + .db 0b10000000 + .db 0b01100000 + + ; ? + .db 0b01100000 + .db 0b00100000 + .db 0b01000000 + + ; @ + .db 0b11000000 + .db 0b10100000 + .db 0b11100000 + + ; A + .db 0b01000000 + .db 0b11100000 + .db 0b10100000 + + ; B + .db 0b11000000 + .db 0b11100000 + .db 0b11000000 + + ; C + .db 0b11100000 + .db 0b10000000 + .db 0b11100000 + + ; D + .db 0b11000000 + .db 0b10100000 + .db 0b11000000 + + ; E + .db 0b11100000 + .db 0b11000000 + .db 0b11100000 + + ; F + .db 0b11100000 + .db 0b11000000 + .db 0b10000000 + + ; G + .db 0b11000000 + .db 0b10100000 + .db 0b11100000 + + ; H + .db 0b10100000 + .db 0b11100000 + .db 0b10100000 + + ; I + .db 0b11100000 + .db 0b01000000 + .db 0b11100000 + + ; J + .db 0b11100000 + .db 0b01000000 + .db 0b11000000 + + ; K + .db 0b10100000 + .db 0b11000000 + .db 0b10100000 + + ; L + .db 0b10000000 + .db 0b10000000 + .db 0b11100000 + + ; M + .db 0b11100000 + .db 0b11100000 + .db 0b10100000 + + ; N + .db 0b11000000 + .db 0b10100000 + .db 0b10100000 + + ; O + .db 0b01000000 + .db 0b10100000 + .db 0b01000000 + + ; P + .db 0b11100000 + .db 0b11100000 + .db 0b10000000 + + ; Q + .db 0b11100000 + .db 0b10100000 + .db 0b11000000 + + ; R + .db 0b11100000 + .db 0b10000000 + .db 0b10000000 + + ; S + .db 0b01100000 + .db 0b01000000 + .db 0b11000000 + + ; T + .db 0b11100000 + .db 0b01000000 + .db 0b01000000 + + ; U + .db 0b10100000 + .db 0b10100000 + .db 0b11100000 + + ; V + .db 0b10100000 + .db 0b10100000 + .db 0b01000000 + + ; W + .db 0b10100000 + .db 0b11100000 + .db 0b11100000 + + ; X + .db 0b10100000 + .db 0b01000000 + .db 0b10100000 + + ; Y + .db 0b10100000 + .db 0b11100000 + .db 0b01000000 + + ; Z + .db 0b11000000 + .db 0b01000000 + .db 0b01100000 + + ; [ + .db 0b11000000 + .db 0b10000000 + .db 0b11000000 + + ; \ + .db 0b10000000 + .db 0b01000000 + .db 0b00100000 + + ; ] + .db 0b01100000 + .db 0b00100000 + .db 0b01100000 + + ; ^ + .db 0b01000000 + .db 0b10100000 + .db 0b00000000 + + ; _ + .db 0b00000000 + .db 0b00000000 + .db 0b11100000 + + ; ` + .db 0b10000000 + .db 0b01000000 + .db 0b00000000 + + ; a + .db 0b01000000 + .db 0b11100000 + .db 0b10100000 + + ; b + .db 0b11000000 + .db 0b11100000 + .db 0b11000000 + + ; c + .db 0b11100000 + .db 0b10000000 + .db 0b11100000 + + ; d + .db 0b11000000 + .db 0b10100000 + .db 0b11000000 + + ; e + .db 0b11100000 + .db 0b11000000 + .db 0b11100000 + + ; f + .db 0b11100000 + .db 0b11000000 + .db 0b10000000 + + ; g + .db 0b11000000 + .db 0b10100000 + .db 0b11100000 + + ; h + .db 0b10100000 + .db 0b11100000 + .db 0b10100000 + + ; i + .db 0b11100000 + .db 0b01000000 + .db 0b11100000 + + ; j + .db 0b11100000 + .db 0b01000000 + .db 0b11000000 + + ; k + .db 0b10100000 + .db 0b11000000 + .db 0b10100000 + + ; l + .db 0b10000000 + .db 0b10000000 + .db 0b11100000 + + ; m + .db 0b11100000 + .db 0b11100000 + .db 0b10100000 + + ; n + .db 0b11000000 + .db 0b10100000 + .db 0b10100000 + + ; o + .db 0b01000000 + .db 0b10100000 + .db 0b01000000 + + ; p + .db 0b11100000 + .db 0b11100000 + .db 0b10000000 + + ; q + .db 0b11100000 + .db 0b10100000 + .db 0b11000000 + + ; r + .db 0b11100000 + .db 0b10000000 + .db 0b10000000 + + ; s + .db 0b01100000 + .db 0b01000000 + .db 0b11000000 + + ; t + .db 0b11100000 + .db 0b01000000 + .db 0b01000000 + + ; u + .db 0b10100000 + .db 0b10100000 + .db 0b11100000 + + ; v + .db 0b10100000 + .db 0b10100000 + .db 0b01000000 + + ; w + .db 0b10100000 + .db 0b11100000 + .db 0b11100000 + + ; x + .db 0b10100000 + .db 0b01000000 + .db 0b10100000 + + ; y + .db 0b10100000 + .db 0b11100000 + .db 0b01000000 + + ; z + .db 0b11000000 + .db 0b01000000 + .db 0b01100000 + + ; { + .db 0b11000000 + .db 0b01100000 + .db 0b11000000 + + ; | + .db 0b01000000 + .db 0b01000000 + .db 0b01000000 + + ; } + .db 0b01100000 + .db 0b11000000 + .db 0b01100000 + + ; ~ + .db 0b01100000 + .db 0b11000000 + .db 0b00000000 From 2eae066163dff3ef016475e1d80c92b93473729b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Oct 2015 09:12:40 -0400 Subject: [PATCH 2/4] Add small font drawing functions --- src/00/base.asm | 35 +++-- src/00/boot.asm | 9 ++ src/01/base.asm | 1 + src/01/jumptable.config | 7 + src/01/smalltext.asm | 323 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 361 insertions(+), 14 deletions(-) create mode 100644 src/01/smalltext.asm diff --git a/src/00/base.asm b/src/00/base.asm index 822072b..d827e2a 100644 --- a/src/00/base.asm +++ b/src/00/base.asm @@ -7,20 +7,27 @@ #include "constants.asm" ; TODO: Use a proper linker instead of this trash -newline .equ 0x0001 -drawChar .equ 0x0101 -drawCharAND .equ 0x0201 -drawCharXOR .equ 0x0301 -drawStr .equ 0x0401 -drawStrAND .equ 0x0501 -drawStrXOR .equ 0x0601 -wrapStr .equ 0x0701 -wrapStrAND .equ 0x0801 -wrapStrXOR .equ 0x0901 -drawHexA .equ 0x0A01 -measureChar .equ 0x0B01 -measureStr .equ 0x0C01 -drawHexHL .equ 0x0E01 +newline .equ 0x0001 +drawChar .equ 0x0101 +drawCharAND .equ 0x0201 +drawCharXOR .equ 0x0301 +drawStr .equ 0x0401 +drawStrAND .equ 0x0501 +drawStrXOR .equ 0x0601 +wrapStr .equ 0x0701 +wrapStrAND .equ 0x0801 +wrapStrXOR .equ 0x0901 +drawHexA .equ 0x0A01 +measureChar .equ 0x0B01 +measureStr .equ 0x0C01 +drawHexHL .equ 0x0E01 +draw3x3Char .equ 0x1101 +draw3x3Str .equ 0x1201 +draw3x3DecA .equ 0x1301 +draw3x3HexA .equ 0x1401 +draw3x3HexHL .equ 0x1501 +draw3x3DecHL .equ 0x1601 +draw3x3DecACIX .equ 0x1701 #include "header.asm" #include "boot.asm" diff --git a/src/00/boot.asm b/src/00/boot.asm index 19c93d9..93d8730 100644 --- a/src/00/boot.asm +++ b/src/00/boot.asm @@ -97,6 +97,15 @@ reboot: call initDisplay call initIO + ld iy, 0xC000 + call clearBuffer + ld hl, init + ld de, 0 + rst 0x20 + .dw draw3x3str + call fastCopy + jr $ + ld de, init call fileExists ld a, panic_init_not_found diff --git a/src/01/base.asm b/src/01/base.asm index a038b68..9e55beb 100644 --- a/src/01/base.asm +++ b/src/01/base.asm @@ -7,6 +7,7 @@ .org 0x4000 #include "text.asm" +#include "smalltext.asm" #include "font.asm" .echo "Bytes remaining on page 01: {0}" 0x8000-$ diff --git a/src/01/jumptable.config b/src/01/jumptable.config index b82fd14..334db96 100644 --- a/src/01/jumptable.config +++ b/src/01/jumptable.config @@ -23,3 +23,10 @@ drawHexHL drawDecHL drawDecACIX + draw3x3Char + draw3x3Str + draw3x3DecA + draw3x3HexA + draw3x3HexHL + draw3x3DecHL + draw3x3DecACIX diff --git a/src/01/smalltext.asm b/src/01/smalltext.asm new file mode 100644 index 0000000..e6b8d89 --- /dev/null +++ b/src/01/smalltext.asm @@ -0,0 +1,323 @@ +;; draw3x3Char [Text] +;; Draws a character to the screen buffer with the 3x3 font. +;; Inputs: +;; IY: Screen buffer +;; A: Character to print +;; D, E: X, Y +;; B: Left margin +;; Outputs: +;; D, E: Moved to next character position +;; Notes: +;; The left margin is only required if your string contains newlines or carriage returns. +draw3x3Char: + push af + push hl + push bc + cp '\n' + jr nz, _ + ld a, e + add a, 6 + ld e, a + ld d, b + jr .exit +_: + cp '\r' + jr nz, _ + ld d, b + jr .exit +_: + cp '\t' + jr nz, _ + ld a, d + add a, 8 + ld d, a + jr .exit +_: + push de + sub 0x20 + ld l, a + ld h, 0 + ld d, h \ ld e, l + add hl, de \ add hl, de + ex de, hl + ld hl, font_3x3 + add hl, de + pop de + ld b, 3 + push af + ld a, d + cp 95 + jr nc, +_ + call putSpriteOR + pop af + ld a, 4 + add a, d + ld d, a +.exit: + pop bc + pop hl + pop af + ret +_: pop af + pop bc + pop hl + pop af + ret + +;; draw3x3Str [Text] +;; Draws a zero-delimited string to the screen buffer using the 3x3 font. +;; Inputs: +;; IY: Screen buffer +;; HL: String +;; D, E: X, Y +;; B: Left margin +;; Outputs: +;; D, E: Advanced to position of the end of the string +;; Notes: +;; The left margin is only required if your string contains newlines or carriage returns. +draw3x3Str: + push hl + push af +_: ld a, (hl) + or a + jr z, _ + call draw3x3Char + inc hl + jr -_ +_: pop af + pop hl + ret + +;; draw3x3HexA [Text] +;; Draws the contents of A in hexadecimal to the screen buffer using the 3x3 font. +;; Inputs: +;; IY: Screen buffer +;; D, E: X, Y +;; A: Value +;; Outputs: +;; D, E: Advanced to position of next character +draw3x3HexA: + push af + rrca + rrca + rrca + rrca + call .dispha + pop af + ; fall into for second call +.dispha: + and 15 + cp 10 + jr nc, .dhlet + add a, 48 + jr .dispdh +.dhlet: + add a, 55 +.dispdh: + jp draw3x3Char + +;; draw3x3DecA [Text] +;; Draws the contents of A in decimal to the screen buffer using the 3x3 font. +;; Inputs: +;; IY: Screen buffer +;; D, E: X, Y +;; A: Value +;; Outputs: +;; D, E: Advanced to position of next character +draw3x3DecA: + push af + push bc + push hl + ; use C to keep track of leading zeroes + ld c, 0 + ; display hundreds + push af + push de + ld e, 100 + ld d, a + call div8By8 + ld a, d + pop de + or a + jr z, .no100 + inc c + ld b, a + add a, '0' + call draw3x3Char + ld a, b + ld b, e + ld e, a + ld h, 100 + call mul8By8 + ld e, b + pop af + sub l + jr .done100 +.no100: + pop af +.done100: + ; display tens + push af + push de + ld e, 10 + ld d, a + call div8By8 + ld a, d + pop de + ld b, a + or a + ; this may not be a leading zero + or c + ld a, b + jr z, .no10 + ld b, a + add a, '0' + call draw3x3Char + ld a, b + ld b, e + ld e, a + ld h, 10 + call mul8By8 + ld e, b + pop af + sub l + jr .done10 +.no10: + pop af +.done10: + ; draw units + add a, '0' + call draw3x3Char + pop hl + pop bc + pop af + ret + +;; draw3x3HexHL [Text] +;; Draws the contents of HL in hexadecimal to the screen buffer using the small font. +;; Inputs: +;; IY: Screen buffer +;; D, E: X, Y +;; HL: Value +;; Outputs: +;; D, E: Advanced to position of next character +draw3x3HexHL: + push af + ld a, h + call draw3x3HexA + ld a, l + call draw3x3HexA + pop af + ret + +;; draw3x3DecHL [Text] +;; Draws the contents of HL in decimal to the screen buffer using the small font. +;; Inputs: +;; IY: Screen buffer +;; D, E: X, Y +;; HL: Value +;; Outputs: +;; D, E: Advanced to position of next character +draw3x3DecHL: + push hl + push bc + push af + ld b, 0 ;Our digit counter +.loop: + push de + ld de, 0 + call cpHLDE + pop de + jr z, _ ;If HL is down to zero, exit loop + ld c, 10 + call divHLByC ;Divide HL by 10... + push af ;Push the remainder to the stack + inc b ;Inc our digit counter + jr .loop +_: + ld a, b + cp 0 + call z, draw3x3DecA ;Draw a Zero if HL is Zero +.draw: + ld a, b + cp 0 + jr z, _ ;if our digit counter is zero, exit loop + pop af ;pop our digit from the stack + call draw3x3DecA ;draw the digit + dec b ;dec our digit counter + jr .draw +_: + pop af + pop bc + pop hl + ret + +;; draw3x3DecACIX [Text] +;; Draws the contents of ACIX in decimal to the screen buffer using the 3x3 font. +;; Inputs: +;; IY: Screen buffer +;; D, E: X, Y +;; ACIX: Value +;; Outputs: +;; D, E: Advanced to position of next character +draw3x3DecACIX: + push af + push ix + push bc + push hl + ld b, 0 ;Our digit counter +.loop: + ;Check if ACIX is zero + push bc + cp 0 + jp nz, .notZero ;If a is not zero + + ld b, a + ld a, c + cp 0 + ld a, b + jp nz, .notZero ;If c is not zero + + ld b, a + ld a, ixh + cp 0 + ld a, b + jp nz, .notZero ;If ixh is not zero + + ld b, a + ld a, ixl + cp 0 + ld a, b + jp nz, .notZero ;If ixl is not zero +.notZero: + pop bc + jr z, _ ;If ACIX is down to zero, exit loop + push de + push iy + ld iyh, b + ld de, 10 + call div32By16 ;Divide ACIX by 10... + ld b, iyh + pop iy + pop de + push hl ;Push the remainder to the stack + inc b ;Inc our digit counter + jr .loop +_: + ld a, b + cp 0 + call z, drawDecA ;Draw a Zero if ACIX is Zero +.draw: + ld a, b + cp 0 + jr z, _ ;if our digit counter is zero, exit loop + pop hl ;pop our digit from the stack + call drawDecHL ;draw the digit + dec b ;dec our digit counter + jr .draw +_: + pop hl + pop bc + pop ix + pop af + ret From 8ab0fc15dbf5e1eb7a6e7644995d7ce4fe45ead4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Oct 2015 09:20:30 -0400 Subject: [PATCH 3/4] Fix newlines --- src/01/smalltext.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/01/smalltext.asm b/src/01/smalltext.asm index e6b8d89..5794e20 100644 --- a/src/01/smalltext.asm +++ b/src/01/smalltext.asm @@ -16,7 +16,7 @@ draw3x3Char: cp '\n' jr nz, _ ld a, e - add a, 6 + add a, 4 ld e, a ld d, b jr .exit From 0dc77992b7073f0e90d5add4dc48820eb22547ff Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Nov 2015 07:16:21 -0500 Subject: [PATCH 4/4] Remove test code from boot.asm --- src/00/boot.asm | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/00/boot.asm b/src/00/boot.asm index 93d8730..19c93d9 100644 --- a/src/00/boot.asm +++ b/src/00/boot.asm @@ -97,15 +97,6 @@ reboot: call initDisplay call initIO - ld iy, 0xC000 - call clearBuffer - ld hl, init - ld de, 0 - rst 0x20 - .dw draw3x3str - call fastCopy - jr $ - ld de, init call fileExists ld a, panic_init_not_found