At Amazon Renewed, every pre-owned or refurbished product is professionally inspected and tested to work and look like new. Here’s how it works: when a customer returns or trades in an item, it is carefully restored by Amazon-qualified suppliers to meet our high standards. We then offer it to you with the Amazon Renewed Guarantee, which includes a replacement or refund if you’re not satisfied.
;======================================================================
; Z80 Retro Computer System Core
;======================================================================
; Hardware Configuration
CRT_CTRL .EQU $10
CRT_DATA .EQU $11
UART_CTRL .EQU $20
UART_DATA .EQU $21
PSG_ADDR .EQU $30
PSG_DATA .EQU $31
; System Variables in RAM
SYS_FLAGS .EQU $8000
CURSOR_X .EQU $8001
CURSOR_Y .EQU $8002
KEY_BUFFER .EQU $8020
;======================================================================
; ROM Entry Point
;======================================================================
.ORG $0000
COLD_BOOT: DI
LD SP, $FFFF
JP SYSTEM_INIT
;======================================================================
; System Initialization
;======================================================================
SYSTEM_INIT:
CALL INIT_VIDEO
CALL INIT_PSG
CALL INIT_UART
EI
JP MAIN_SHELL
;======================================================================
; Video Subsystem
;======================================================================
INIT_VIDEO:
LD A, $1F
OUT (CRT_CTRL), A
LD A, $03
OUT (CRT_CTRL), A
RET
CLEAR_SCREEN:
LD HL, $C000
LD DE, $C001
LD BC, $07FF
LD (HL), ‘ ‘
LDIR
RET
SCROLL_UP:
PUSH BC
LD HL, $C040
LD DE, $C000
LD BC, $07C0
LDIR
POP BC
RET
;======================================================================
; PSG Sound System
;======================================================================
INIT_PSG:
LD A, $07
OUT (PSG_ADDR), A
LD A, $3F
OUT (PSG_DATA), A
RET
BEEP:
LD A, $00
OUT (PSG_ADDR), A
LD A, $FF
OUT (PSG_DATA), A
LD A, $01
OUT (PSG_ADDR), A
LD A, $00
OUT (PSG_DATA), A
LD A, $07
OUT (PSG_ADDR), A
LD A, $3E
OUT (PSG_DATA), A
RET
;======================================================================
; UART Communication
;======================================================================
INIT_UART:
LD A, $03
OUT (UART_CTRL), A
LD A, $17
OUT (UART_CTRL), A
RET
UART_TX:
PUSH AF
TX_BUSY: IN A, (UART_CTRL)
BIT 1, A
JR Z, TX_BUSY
POP AF
OUT (UART_DATA), A
RET
UART_RX:
IN A, (UART_CTRL)
BIT 0, A
RET Z
IN A, (UART_DATA)
RET
;======================================================================
; Main System Shell
;======================================================================
MAIN_SHELL:
CALL CLEAR_SCREEN
LD HL, BANNER_MSG
CALL PRINT_STRING
SHELL_LOOP: LD A, ‘>’
CALL PRINT_CHAR
CALL READ_LINE
CALL PARSE_CMD
JR SHELL_LOOP
;======================================================================
; Utility Functions
;======================================================================
PRINT_CHAR:
PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL UART_TX
POP HL
POP DE
POP BC
POP AF
RET
PRINT_STRING:
LD A, (HL)
AND A
RET Z
CALL PRINT_CHAR
INC HL
JR PRINT_STRING
;======================================================================
; Data Section
;======================================================================
BANNER_MSG: .DB 13,10,”Z80 SYSTEM READY”,13,10,0
PROMPT_MSG: .DB “>”,0
;======================================================================
; Interrupt Vectors
;======================================================================
.ORG $0038
EI
RETI
.ORG $0066
RETN