git-svn-id: http://moon:8086/svn/vhdl/trunk@1414 cc03376c-175c-47c8-b038-4cd826a8556b
284 lines
5.3 KiB
JavaScript
284 lines
5.3 KiB
JavaScript
; -------------------------------------------------
|
|
; Register definitions
|
|
; -------------------------------------------------
|
|
include "../../../lib/jasm/cregs.inc.jsm"
|
|
include "xregs.inc.jsm"
|
|
|
|
; -------------------------------------------------
|
|
; Constants
|
|
; -------------------------------------------------
|
|
CR: equ 0x0D
|
|
LF: equ 0x0A
|
|
report_ival: equ 0x64
|
|
|
|
; External RAM/ROM
|
|
xmem
|
|
msg_txt: dc "J-CPU V1.", 0
|
|
|
|
; Internal RAM
|
|
cmem 0
|
|
count: db 4
|
|
|
|
cntDigit: db 8
|
|
|
|
count_stat: db 1
|
|
shifter: db 1
|
|
|
|
ram_txt_start: db 15
|
|
ram_txt_end: db 1
|
|
ram_txt_ptr: db 1
|
|
upd_z1: db 1
|
|
page_test_var: db 1
|
|
|
|
; -------------------------------------------------
|
|
; Program
|
|
; -------------------------------------------------
|
|
code
|
|
reset: org 0x000
|
|
jmp ende
|
|
|
|
org 1023
|
|
ende: jmp init
|
|
|
|
org 0x001
|
|
; -------------------------------------------------
|
|
; ISR
|
|
; -------------------------------------------------
|
|
isr: push R0
|
|
push R1
|
|
push R2
|
|
push R3
|
|
push R4
|
|
push R5
|
|
push R6
|
|
push R7
|
|
push R8
|
|
push R9
|
|
push R10
|
|
push R11
|
|
push R12
|
|
push R13
|
|
push R14
|
|
push R15
|
|
|
|
xin R0, (uart_status)
|
|
and R0, 0x10
|
|
jz rcv_empty
|
|
xin R0, (uart_data)
|
|
cmp R0, 0x0D
|
|
jeq reset_ptr
|
|
movc R1, (ram_txt_ptr)
|
|
movc (R1), R0
|
|
cmp R1, ram_txt_end
|
|
jlt inc_ptr
|
|
reset_ptr: mov R1, ram_txt_start
|
|
dec R1
|
|
movc (upd_z1), R1
|
|
inc_ptr: inc R1
|
|
movc (ram_txt_ptr), R1
|
|
rcv_empty: call Cnt32
|
|
|
|
pop R15
|
|
pop R14
|
|
pop R13
|
|
pop R12
|
|
pop R11
|
|
pop R10
|
|
pop R9
|
|
pop R8
|
|
pop R7
|
|
pop R6
|
|
pop R5
|
|
pop R4
|
|
pop R3
|
|
pop R2
|
|
pop R1
|
|
pop R0
|
|
reti
|
|
|
|
; -------------------------------------------------
|
|
; Main
|
|
; -------------------------------------------------
|
|
init: ; org 0x40
|
|
|
|
call CounterInit
|
|
call LCD_init
|
|
mov R0, 0x00
|
|
movc (count_stat), R0
|
|
xout (led_port), R0
|
|
movc (upd_z1), R0
|
|
xin R1, (btn_port)
|
|
or R1, 0x80
|
|
movc (shifter), R1
|
|
mov R0, ram_txt_start
|
|
movc (ram_txt_ptr), R0
|
|
|
|
mov R0, ctrl_reg
|
|
; Enable timer
|
|
xout (R0), 0x02
|
|
; Enable interrupt source
|
|
xout (R0), 0x03
|
|
mov R0, report_ival
|
|
movc (count_stat), R0
|
|
|
|
; Enable CPU interrupt
|
|
mov R0, 0x03
|
|
cout (cpu_int_ctrl), R0
|
|
|
|
; Print Hello world
|
|
mov R0, LCD_CMD_CLEAR
|
|
call LCD_writecmd
|
|
mov R1, msg_txt
|
|
call LCD_putsx
|
|
|
|
; Read revision reg to form version number v1.<REV>
|
|
end_txt: cin R0, (cpu_revision)
|
|
add R0, 0x30
|
|
call LCD_writechar
|
|
|
|
; check page sel function
|
|
mov R0, 0x00
|
|
cout (cpu_control), R0
|
|
mov R1, 0x00
|
|
movc (page_test_var), R1
|
|
|
|
mov R0, 0x01
|
|
cout (cpu_control), R0
|
|
mov R1, 0xAA
|
|
movc (page_test_var), R1
|
|
|
|
mov R0, 0x00
|
|
cout (cpu_control), R0
|
|
movc R0, (page_test_var)
|
|
cmp R0, 0xAA
|
|
jeq error
|
|
|
|
mov R0, 0x01
|
|
cout (cpu_control), R0
|
|
movc R0, (page_test_var)
|
|
cmp R0, 0xAA
|
|
jeq page_reset
|
|
|
|
error: jmp error
|
|
|
|
page_reset: mov R0, 0x00
|
|
cout (cpu_control), R0
|
|
|
|
; -------------------------------------------------
|
|
; Main loop
|
|
; -------------------------------------------------
|
|
start: halt
|
|
|
|
movc R0, (count_stat)
|
|
dec R0
|
|
movc (count_stat), R0
|
|
jnz start
|
|
mov R7, report_ival
|
|
movc R1, (cntDigit+0)
|
|
movc R2, (cntDigit+1)
|
|
swap R1
|
|
xor R1, R2
|
|
and R1, 0x02
|
|
jnz do_add
|
|
dec R7
|
|
mov R0, 0x2D
|
|
jmp upd_cs
|
|
|
|
do_add: inc R7
|
|
mov R0, 0x2B
|
|
upd_cs: movc (count_stat), R7
|
|
call sout
|
|
|
|
; Toggle LED
|
|
movc R0, (shifter)
|
|
rol R0
|
|
movc (shifter), R0
|
|
|
|
; xin R0, (led_port)
|
|
; xor R0, 0x02
|
|
xout (led_port), R0
|
|
|
|
movc R0, (upd_z1)
|
|
mov R1, 0x00
|
|
movc (upd_z1), R1
|
|
tst R0
|
|
jz upd_num
|
|
|
|
mov R1, ram_txt_start
|
|
read_ram: movc R0, (R1)
|
|
call LCD_writechar
|
|
inc R1
|
|
cmp R1, ram_txt_end
|
|
jle read_ram
|
|
|
|
; Write digits to LCD and serial
|
|
upd_num: call UpdateDigits
|
|
mov R0, LCD_CMD_Z2
|
|
call LCD_writecmd
|
|
mov R1, cntDigit+7
|
|
print_num: movc R0, (R1)
|
|
call sout
|
|
call LCD_writechar
|
|
cmp R1, cntDigit+0
|
|
jeq sendCRLF
|
|
dec R1
|
|
jmp print_num
|
|
|
|
sendCRLF: mov R0, CR
|
|
call sout
|
|
mov R0, LF
|
|
call sout
|
|
|
|
ex_print: jmp start
|
|
|
|
; -------------------------------------------------
|
|
CounterInit: mov R0, 0x00
|
|
movc (count+0), R0
|
|
movc (count+1), R0
|
|
movc (count+2), R0
|
|
movc (count+3), R0
|
|
ret
|
|
|
|
; -------------------------------------------------
|
|
Cnt32: mov R0, count+0
|
|
cloop: movc R1, (R0)
|
|
inc R1
|
|
movc (R0), R1
|
|
jnc CountRdy
|
|
cmp R0, count+3
|
|
jeq CountRdy
|
|
inc R0
|
|
jmp cloop
|
|
CountRdy: ret
|
|
|
|
; -------------------------------------------------
|
|
UpdateDigits: mov R2, cntDigit+0
|
|
mov R0, count+0
|
|
dualLoop: movc R1, (R0)
|
|
and R1, 0x0F
|
|
cmp R1, 0x0A
|
|
jlt isNum1
|
|
add R1, 0x07
|
|
isNum1: add R1, 0x30
|
|
movc (R2), R1
|
|
inc R2
|
|
movc R1, (R0)
|
|
swap R1
|
|
and R1, 0x0F
|
|
cmp R1, 0x0A
|
|
jlt isNum2
|
|
add R1, 0x07
|
|
isNum2: add R1, 0x30
|
|
movc (R2), R1
|
|
cmp R0, count+3
|
|
jeq UpdRdy
|
|
inc R0
|
|
inc R2
|
|
jmp dualLoop
|
|
UpdRdy: ret
|
|
|
|
; -------------------------------------------------
|
|
include "../../../lib/jasm/uart.inc.jsm"
|
|
include "../../../lib/jasm/lcd.inc.jsm"
|
|
include "../../../lib/jasm/delays.inc.jsm"
|
|
|