putchar.s (2428B)
1 .include "global.s" 2 3 .title "putchar" 4 .module putchar 5 6 .globl font_current, font_set, font_load_ibm 7 .globl .scroll_viewport 8 9 ; Structure offsets 10 sfont_handle_sizeof = 3 11 sfont_handle_font = 1 12 sfont_handle_first_tile = 0 13 14 ; Encoding types - lower 2 bits of font 15 FONT_256ENCODING = 0 16 FONT_128ENCODING = 1 17 FONT_NOENCODING = 2 18 19 .area _INITIALIZED 20 ; The current font 21.curx:: 22 .ds 1 23.cury:: 24 .ds 1 25 26 .area _INITIALIZER 27 .db #.SCREEN_X_OFS ; .curx 28 .db #.SCREEN_Y_OFS ; .cury 29 30 .area _HOME 31 32_setchar:: 33_putchar:: 34 pop hl 35 pop de 36 push de 37 push hl 38 39 ld a, e 40 cp #.CR 41 jr nz, 0$ 42 43 ld a, #.SCREEN_X_OFS 44 ld (.curx), a 45 jp 2$ 460$: 47 ld hl, (font_current+sfont_handle_font) 48 ld a, h 49 or l 50 jr nz, 6$ 51 52 push de 53 call font_load_ibm 54 ld a, h 55 or l 56 ret z 57 call font_set 58 pop de 59 ld hl, (font_current+sfont_handle_font) 606$: 61 ld a, (hl) 62 and #3 63 cp #FONT_NOENCODING 64 jr z, 4$ 65 inc hl 66 inc hl 67 ld d, #0 68 add hl, de 69 ld e, (hl) 704$: 71 ld a, (font_current) 72 add a, e 73 ld e, a 74 75 ld a, (.cury) 76 ld l, a 77 ld h, #0 78 add hl, hl 79 add hl, hl 80 add hl, hl 81 add hl, hl 82 add hl, hl 83 add hl, hl 84 ld a, (.curx) 85 add a 86 add l 87 ld l, a 88 adc h 89 sub l 90 ld h, a 91 92 ld bc, #.VDP_TILEMAP 93 add hl, bc 94 95 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT 96 WRITE_VDP_CMD_HL 97 98 ld a, e 99 out (.VDP_DATA), a 100 VDP_DELAY 101 xor a 102 out (.VDP_DATA), a 103 104 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT 105 106 ld a, (.curx) 107 inc a 108 cp #(.SCREEN_X_OFS + .SCREEN_WIDTH) 109 jr c, 5$ 110 ld a, #.SCREEN_X_OFS 1115$: 112 ld (.curx), a 113 ret nz 1142$: 115 ld a, (.cury) 116 inc a 117 cp #(.SCREEN_Y_OFS + .SCREEN_HEIGHT) 118 jr c, 3$ 119 ld a, #(.SCREEN_Y_OFS + .SCREEN_HEIGHT - 1) 120 ld (.cury), a 121 122 call .scroll_viewport 123 ret 1243$: 125 ld (.cury), a 126 ret