Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CPU_65202.CPU"
- ROM_START = 0x000000
- IO_START = 0x000000
- RAM_START = ROM_START + 0x400
- DEFAULT_N_PAGE = RAM_START
- STACK_START = RAM_START + 0x200
- STR_SPACE = RAM_START + 0x300
- TERM = IO_START ; Serial Terminal
- KEYB = IO_START ; Serial Keyboard
- KEYS = IO_START + 1 ; Keyboard Status
- EXTR = IO_START + 1 ; Something else
- INT_VAR_0 = DEFAULT_N_PAGE
- INT_VAR_1 = DEFAULT_N_PAGE + 2
- INT_VAR_2 = DEFAULT_N_PAGE + 4
- INT_VAR_3 = DEFAULT_N_PAGE + 6
- INT_VAR_4 = DEFAULT_N_PAGE + 8
- INT_VAR_5 = DEFAULT_N_PAGE + 10
- INT_VAR_6 = DEFAULT_N_PAGE + 12
- INT_VAR_7 = DEFAULT_N_PAGE + 14
- STR_PNT_0 = DEFAULT_N_PAGE + 0x80
- STR_PNT_1 = DEFAULT_N_PAGE + 0x80 + 3
- STR_PNT_2 = DEFAULT_N_PAGE + 0x80 + 6
- STR_PNT_3 = DEFAULT_N_PAGE + 0x80 + 9
- ASCII_ZERO = 0x30
- ASCII_LF = 0x0A
- INIT:
- DI
- LD A, 0x0000
- LD X, A
- LD Y, A
- LD SN, STACK_START[23:16]
- LD SP, STACK_START[15:0]
- LD N, DEFAULT_N_PAGE[23:8]
- LD ITP, INT_VECTORS
- CLF
- EI
- JMP START
- INT_VECTORS:
- #d24 INT_HANDLER[23:0] ; INT Vector
- #d24 NMI_HANDLER[23:0] ; NMI Vector
- INT_HANDLER:
- RET
- NMI_HANDLER:
- RET
- START:
- LD [STR_PNT_0], STR_SPACE[23:16]
- LD [STR_PNT_0 + 1], STR_SPACE[15:8]
- LD [STR_PNT_0 + 2], STR_SPACE[7:0]
- LD XL, ASCII_LF
- CALL GET_STR
- CALL PRINT_STR
- HALT
- CNT_MEM_STR:
- ;#str "kB of Memory detected\n\0"
- CNT_MEM: ; Counts the amount of RAM in the system in kB (banked RAM ignored), starts from RAM_START, uses (INT_VAR_0) and the bottom half of INT_VAR_1
- RET
- PRINT_STR: ; Prints a String to (TERM) from the address stored at (STR_PNT_0), Strings are Null Terminated
- DXO
- PUSH YL
- LD YL, 0x00
- .LOOP:
- LD AL, ([STR_PNT_0], Y)
- CMP 0x00
- JR Z .EXIT
- OUT (TERM), AL
- INC YL
- JR NO .LOOP
- LD AL, 0xFF
- POP YL
- RET
- .EXIT:
- LD AL, 0x00
- POP YL
- RET
- GET_STR: ; Stores a String from (KEYB) to Memory using the address stored at (STR_PNT_0) until the read byte equals XL, then it replaces that byte with 0x00
- DXO
- PUSH YL
- LD YL, 0x00
- .LOOP:
- .WAIT_DATA:
- IN AL, (KEYS)
- CMP XL
- JR Za .WAIT_DATA
- JR Z .EXIT
- LD ([STR_PNT_0], Y), AL
- INC YL
- JR NO .LOOP
- LD AL, 0xFF
- POP YL
- RET
- .EXIT:
- LD AL, 0x00
- LD ([STR_PNT_0], Y), AL
- POP YL
- RET
- CMP_STR: ; Compares 2 Strings from (STR_PNT_0) and (STR_PNT_1) until both strings end with 0x00 or one with 0x00 and the other with XL
- RET
- INT8_STR: ; Converts an 8-bit Integer from the bottom half of INT_VAR_0 into a string stored at (STR_PNT_0), string is null-terminated
- RET
- INT16_STR: ; Converts a 16-bit Integer from INT_VAR_0 into a string stored at (STR_PNT_0), string is null-terminated
- RET
- IMUL_8: ; Multiplies 2 8-Bit Integers from the bottom half of INT_VAR_0 and INT_VAR_1 and stores the result in AL
- RET
- IMUL_16: ; Multiplies 2 16-Bit Integers from INT_VAR_0 and INT_VAR_1 and stores the result in A
- RET
- IDIV_8: ; Divides 2 8-Bit Integers from the bottom half of INT_VAR_0 and INT_VAR_1 (INT_VAR_0 / INT_VAR_1 = AL) and stores the result in AL (remainder in Y)
- RET
- IDIV_16: ; Divides 2 16-Bit Integers from INT_VAR_0 and INT_VAR_1 (VAR_0 / VAR_1 = A) and stores the result in A (remainder in XY)
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement