-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.asm
117 lines (100 loc) · 4.43 KB
/
console.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
; Constants
; -----------------------------------------------------------------------------
lcd_command equ $00 ; LCD command I/O port (Y0.0)
lcd_data equ $01 ; LCD data I/O port (Y0.1)
ps2_command equ $20 ; Arduino PS/2 interface port (Y1)
row_offset equ $10 ; 1 framebuffer row = 16 bytes (32 4-bit characters)
; Addresses and pointers
; -----------------------------------------------------------------------------
ram_start equ $2000 ; The lowest address in the RAM
ram_top equ $7fff ; The highest address in the RAM
buffer equ $2000 ; The text content of the console buffer (1024 bytes)
framebuffer equ $3000 ; The LCD framebuffer (1024 bytes)
buffer_pointer equ $4000 ; The current location in the text buffer (2 bytes)
fb_offset equ $4002 ; The offset for a particular buffer location in the framebuffer (2 bytes)
char_offset equ $4004 ; The start address of the current framebuffer character (2 bytes)
cmd_buffer_pointer equ $4006 ; The current location in the command buffer (1 byte)
fb_pointer equ $4008 ; The current location in the framebuffer (2 bytes)
remaining_bytes equ $4010 ; A counter of remaining bytes in a particular line (1 byte)
row_end equ $4012 ; The end location of the current row (2 bytes)
cmd_buffer equ $5000 ; The current command buffer (255 bytes)
org $0 ; Z80 starts reading here so we send it to the right location
jp setup
org $100
setup:
ld sp,ram_top ; Initialize the stack pointer at the top of RAM
; im 1 ; Set interrupt mode 1 (go to $0038 on interrupt)
; ei ; Enable interrupts
; Reset memory
ld hl,0
ld (buffer_pointer),hl
ld (fb_pointer),hl
ld (fb_offset),hl
ld (char_offset),hl
ld (cmd_buffer_pointer),hl
ld (remaining_bytes),hl
ld (row_end),hl
; ld ix,0
; call buffer_fill
call framebuffer_fill
call lcd_initialise ; Setup LCD display
; ld hl,welcome_message ; Place welcome message into buffer
; call string_length ; Get length of HL string into BC
; ld hl,welcome_message ; Place welcome message into buffer
; call buffer_write_string ; Write string into buffer
; ld hl,-1
; ld (fb_pointer),hl ; To account for increment when subroutine starts
; call send_buffer_to_framebuffer
call lcd_send_buffer
main_loop:
halt
jp main_loop
send_buffer_to_framebuffer_done:
call lcd_send_buffer
jp main_loop
; Get length of null-terminated string stored in memory.
; -----------------------------------------------------------------------------
; HL - start address of the string.
;
; Output:
; BC - length of the string.
; HL - corrupt.
; A - corrupt.
; -----------------------------------------------------------------------------
string_length:
ld bc,-1
dec hl
string_length_loop:
inc bc
inc hl
ld a,(hl)
cp 0 ; Is the current character the null terminator?
jp nz,string_length_loop
ret
delay:
push af
push bc
push de
LD BC, $64 ;Loads BC with hex 1000
Outer:
LD DE, $64 ;Loads DE with hex 1000
Inner:
DEC DE ;Decrements DE
LD A, D ;Copies D into A
OR E ;Bitwise OR of E with A (now, A = D | E)
JP NZ, Inner ;Jumps back to Inner: label if A is not zero
DEC BC ;Decrements BC
LD A, B ;Copies B into A
OR C ;Bitwise OR of C with A (now, A = B | C)
JP NZ, Outer ;Jumps back to Outer: label if A is not zero
pop de
pop bc
pop af
RET ;Return from call to this subroutine
; Data
; -----------------------------------------------------------------------------
welcome_message:
; db "HEX-80 ready",$0A,"> ",0
db "Hello world!",0
include "lib/ST7920.asm"
align 8192 ; Pad remaining ROM space with $ff