Created
April 26, 2012 03:45
-
-
Save kevinastock/2495625 to your computer and use it in GitHub Desktop.
DCPU Hardware test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; define where the screen is | |
:screen .equ 0x8000 | |
; i : hardware id counter | |
set i, 0 | |
hwn j | |
:setup ; inspect all connected devices, setup recognized ones | |
ife i, j | |
set pc, main | |
hwq i | |
; LEM1802 Low Energy Monitor | |
ife b, 0x7349 | |
ife a, 0xf615 | |
set pc, setup_lem1802 | |
; Generic Keyboard (compatible) | |
ife b, 0x30cf | |
ife a, 0x7406 | |
set pc, setup_keyboard | |
; Generic Clock (compatible) | |
ife b, 0x12d0 | |
ife a, 0xb402 | |
set pc, setup_clock | |
:setup_next | |
add i, 1 | |
set pc, setup | |
:lem1802 dat 0x0 | |
:setup_lem1802 | |
set [lem1802], i | |
; set the video buffer | |
set a, 0 | |
set b, screen | |
hwi i | |
; draw a border | |
set a, 3 | |
set b, 0x9 | |
hwi i | |
set pc, setup_next | |
:keyboard dat 0x0 | |
:setup_keyboard | |
set [keyboard], i | |
; call an interrupt on events with msg 0xdead | |
set a, 3 | |
set b, 0xdead | |
hwi i | |
set pc, setup_next | |
:clock dat 0x0 | |
:setup_clock | |
set [clock], i | |
; tick the clock once per second | |
set a, 0 | |
set b, 60 | |
hwi i | |
; send an interrupt at every tick | |
set a, 2 | |
set b, 0xbeef | |
hwi i | |
; draw an x in the top right if the clock is detected | |
set [screen+31], 0x7000 | 'x' | |
set pc, setup_next | |
:main | |
; ISR will handle interrupts | |
ias ISR | |
; i : middle of second row for "XXXX A" display | |
; b : color mask for "XXXX" | |
set i, 13+32 | |
set b, 0x7000 | |
:loop | |
; check if a key has been pressed | |
set a, 1 | |
hwi [keyboard] | |
ife c, 0 | |
set pc, loop | |
; we got a key, draw its hex value | |
jsr draw_hex | |
; and draw the character for the received key | |
bor c, 0x3000 | |
set [screen+i+5], c | |
set pc, loop | |
; count the number of times this interrupt has been called | |
:counter dat 0x0 | |
:ISR | |
; disable concurrent interrupts | |
ias 0 | |
; back up some values | |
set push, c | |
set push, i | |
set push, b | |
add [counter], 1 | |
; draw the interrupt message on 4th row | |
set c, a | |
set i, 13+32*3 | |
set b, 0xa000 | |
jsr draw_hex | |
; draw the counter on 5th row | |
set c, [counter] | |
set i, 13+32*4 | |
set b, 0xc000 | |
jsr draw_hex | |
; restore and return | |
set b, pop | |
set i, pop | |
set c, pop | |
set a, pop | |
ias ISR | |
set pc, pop | |
:draw_hex ;write the word in c to [screen+i] with bor mask b | |
set push, j | |
set push, c | |
set j, 0 | |
add i, 4 | |
:draw_hex_loop | |
ife j, 16 | |
set pc, end_draw_hex | |
sub i, 1 | |
set c, peek | |
shr c, j | |
and c, 0xf | |
ifl c, 0xa | |
add c, '0' | |
ifl c, 0x10 | |
add c, 'a'-10 | |
bor c, b | |
set [screen+i], c | |
add j, 4 | |
set pc, draw_hex_loop | |
:end_draw_hex | |
set c, pop | |
set j, pop | |
set pc, pop | |
; ============================================== | |
; Binary from code compiled w/ optimizations | |
; ============================================== | |
DAT 0x84c1 ; 0x0000 | |
DAT 0x1e00 ; 0x0001 | |
DAT 0x1cd2 ; 0x0002 | |
DAT 0x7f81 ; 0x0003 | |
DAT 0x0036 ; 0x0004 | |
DAT 0x1a20 ; 0x0005 | |
DAT 0x7c32 ; 0x0006 | |
DAT 0x7349 ; 0x0007 | |
DAT 0x7c12 ; 0x0008 | |
DAT 0xf615 ; 0x0009 | |
DAT 0xe781 ; 0x000a | |
DAT 0x7c32 ; 0x000b | |
DAT 0x30cf ; 0x000c | |
DAT 0x7c12 ; 0x000d | |
DAT 0x7406 ; 0x000e | |
DAT 0xd382 ; 0x000f | |
DAT 0x7c32 ; 0x0010 | |
DAT 0x12d0 ; 0x0011 | |
DAT 0x7c12 ; 0x0012 | |
DAT 0xb402 ; 0x0013 | |
DAT 0xdf82 ; 0x0014 | |
DAT 0x88c2 ; 0x0015 | |
DAT 0x8f81 ; 0x0016 | |
DAT 0x0000 ; 0x0017 | |
DAT 0x1bc1 ; 0x0018 | |
DAT 0x0017 ; 0x0019 | |
DAT 0x8401 ; 0x001a | |
DAT 0x7c21 ; 0x001b | |
DAT 0x8000 ; 0x001c | |
DAT 0x1a40 ; 0x001d | |
DAT 0x9001 ; 0x001e | |
DAT 0xa821 ; 0x001f | |
DAT 0x1a40 ; 0x0020 | |
DAT 0xdb81 ; 0x0021 | |
DAT 0x0000 ; 0x0022 | |
DAT 0x1bc1 ; 0x0023 | |
DAT 0x0022 ; 0x0024 | |
DAT 0x9001 ; 0x0025 | |
DAT 0x7c21 ; 0x0026 | |
DAT 0xdead ; 0x0027 | |
DAT 0x1a40 ; 0x0028 | |
DAT 0xdb81 ; 0x0029 | |
DAT 0x0000 ; 0x002a | |
DAT 0x1bc1 ; 0x002b | |
DAT 0x002a ; 0x002c | |
DAT 0x8401 ; 0x002d | |
DAT 0x7c21 ; 0x002e | |
DAT 0x003c ; 0x002f | |
DAT 0x1a40 ; 0x0030 | |
DAT 0x8c01 ; 0x0031 | |
DAT 0x7c21 ; 0x0032 | |
DAT 0xbeef ; 0x0033 | |
DAT 0x1a40 ; 0x0034 | |
DAT 0xdb81 ; 0x0035 | |
DAT 0x7d40 ; 0x0036 | |
DAT 0x0049 ; 0x0037 | |
DAT 0x7cc1 ; 0x0038 | |
DAT 0x002d ; 0x0039 | |
DAT 0x7c21 ; 0x003a | |
DAT 0x7000 ; 0x003b | |
DAT 0x8801 ; 0x003c | |
DAT 0x7a40 ; 0x003d | |
DAT 0x0022 ; 0x003e | |
DAT 0x8452 ; 0x003f | |
DAT 0x9b83 ; 0x0040 | |
DAT 0x7c20 ; 0x0041 | |
DAT 0x0065 ; 0x0042 | |
DAT 0x7c4a ; 0x0043 | |
DAT 0x3000 ; 0x0044 | |
DAT 0x0ac1 ; 0x0045 | |
DAT 0x8005 ; 0x0046 | |
DAT 0xb783 ; 0x0047 | |
DAT 0x0000 ; 0x0048 | |
DAT 0x8540 ; 0x0049 | |
DAT 0x0b01 ; 0x004a | |
DAT 0x1b01 ; 0x004b | |
DAT 0x0701 ; 0x004c | |
DAT 0x8bc2 ; 0x004d | |
DAT 0x0048 ; 0x004e | |
DAT 0x0041 ; 0x004f | |
DAT 0x7cc1 ; 0x0050 | |
DAT 0x006d ; 0x0051 | |
DAT 0x7c21 ; 0x0052 | |
DAT 0xa000 ; 0x0053 | |
DAT 0x7c20 ; 0x0054 | |
DAT 0x0065 ; 0x0055 | |
DAT 0x7841 ; 0x0056 | |
DAT 0x0048 ; 0x0057 | |
DAT 0x7cc1 ; 0x0058 | |
DAT 0x008d ; 0x0059 | |
DAT 0x7c21 ; 0x005a | |
DAT 0xc000 ; 0x005b | |
DAT 0x7c20 ; 0x005c | |
DAT 0x0065 ; 0x005d | |
DAT 0x6021 ; 0x005e | |
DAT 0x60c1 ; 0x005f | |
DAT 0x6041 ; 0x0060 | |
DAT 0x6001 ; 0x0061 | |
DAT 0x7d40 ; 0x0062 | |
DAT 0x0049 ; 0x0063 | |
DAT 0x6381 ; 0x0064 | |
DAT 0x1f01 ; 0x0065 | |
DAT 0x0b01 ; 0x0066 | |
DAT 0x84e1 ; 0x0067 | |
DAT 0x94c2 ; 0x0068 | |
DAT 0xc4f2 ; 0x0069 | |
DAT 0xc382 ; 0x006a | |
DAT 0x88c3 ; 0x006b | |
DAT 0x6441 ; 0x006c | |
DAT 0x1c4c ; 0x006d | |
DAT 0xc049 ; 0x006e | |
DAT 0xac56 ; 0x006f | |
DAT 0x7c42 ; 0x0070 | |
DAT 0x0030 ; 0x0071 | |
DAT 0xc456 ; 0x0072 | |
DAT 0x7c42 ; 0x0073 | |
DAT 0x0057 ; 0x0074 | |
DAT 0x044a ; 0x0075 | |
DAT 0x0ac1 ; 0x0076 | |
DAT 0x8000 ; 0x0077 | |
DAT 0x94e2 ; 0x0078 | |
DAT 0xcb83 ; 0x0079 | |
DAT 0x6041 ; 0x007a | |
DAT 0x60e1 ; 0x007b | |
DAT 0x6381 ; 0x007c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment