Files
vhdl/projects/cpu/asm/pen_test.jsm
T
jens ea60299d26 - added
git-svn-id: http://moon:8086/svn/vhdl/trunk@1414 cc03376c-175c-47c8-b038-4cd826a8556b
2021-03-21 10:47:01 +00:00

773 lines
16 KiB
JavaScript

; -------------------------------------------------
; Register definitions
; -------------------------------------------------
include "../../../lib/jasm/cregs.inc.jsm"
include "xregs.inc.jsm"
; -------------------------------------------------
; Constants
; -------------------------------------------------
BURST_LEN: equ 8
SD_CMD_WRITE: equ 0x06
SD_CMD_READ: equ 0x05
START_ADDR0: equ 0x00
START_ADDR1: equ 0x00
START_ADDR2: equ 0x20
END_ADDR0: equ 0xF8
END_ADDR1: equ 0xFF
END_ADDR2: equ 0xFF
PEN_TIMEOUT0: equ 0xE8
PEN_TIMEOUT1: equ 0x03
PEN_BUFSIZE: equ 64
; External RAM/ROM
xmem
crlf: dc 13, 10, 0
greet_txt: dc "SDRAM Test", 0
msg_txt0: dc "Clearing SDRAM", 0
msg_txt1: dc "Writing SDRAM", 0
msg_txt2: dc "Reading SDRAM", 0
msg_txt3: dc "Reading Bitmap", 0
verify_ok: dc "Verify OK", 0
verify_nok: dc "Failed at ", 0
dot: dc ".", 0
org 0x80
sdram_data: db 8 ; SDRAM data window at X:0x80
; Internal RAM
cmem 0
block_cnt: db 1
round_cnt: db 1
bmp_offset: db 4
pixel_buf: db 32
pen_rx_buf: db 128
pen_rx_ptr_r: db 1
pen_rx_ptr_w: db 1
pen_timeout: db 2
pen_bit_cnt_w: db 1
pen_octet_w: db 1
pen_octet_r: db 1
pen_last_state: db 1
pen_enable: db 1
pen_bit_cnt_r: db 1
; -------------------------------------------------
; Program
; -------------------------------------------------
code
reset: org 0x000
jmp main
; -------------------------------------------------
; ISR
; -------------------------------------------------
org 0x001
pen_isr: push R0
push R1
push R2
u_get_nxt: xin R1, (btn_port)
movc R0, (pen_octet_w)
and R1, 0x20
shl R1
shl R1
shl R1
rolc R0
movc (pen_octet_w), R0
movc R1, (pen_bit_cnt_w)
inc R1
movc (pen_bit_cnt_w), R1
cmp R1, 8
jne ex_uart_isr
mov R1, 0
movc (pen_bit_cnt_w), R1
movc R2, (pen_rx_ptr_w)
movc (R2), R0
inc R2
cmp R2, pen_rx_buf+128
jne u_upd_nxt
mov R2, pen_rx_buf
u_upd_nxt: movc (pen_rx_ptr_w), R2
ex_uart_isr: call Timer_isr
pop R2
pop R1
pop R0
reti
Timer_isr: xin R0, (btn_port)
and R0, 0x20
shr R0
xin R1, (ctrl_reg)
and R1, 0xEF
or R0, R1
xout (ctrl_reg), R0
xin R0, (btn_port)
and R0, 0x01
jz btn_chk2
mov R0, vga_read_addr
xout (R0), 0x00
inc R0
xout (R0), 0x00
inc R0
xout (R0), 0x00
jmp ex_t_isr
btn_chk2: xin R0, (btn_port)
and R0, 0x02
jz ex_t_isr
mov R0, vga_read_addr
xout (R0), 0x00
inc R0
xout (R0), 0x00
inc R0
xout (R0), 0x20
ex_t_isr: ret
; -------------------------------------------------
; Main
; -------------------------------------------------
main: call pen_init
call LCD_init
mov R0, 0x00
xout (led_port), R0
mov R0, CTRL_VGA_ENABLE
xout (ctrl_reg), R0
xin R0, (ctrl_reg)
or R0, CTRL_TIMER_ENABLE
xout (ctrl_reg), R0
mov R0, 0x03
cout (cpu_int_ctrl), R0
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R0, 0
mov R1, 0xC0
xout (reg_color_red), R1
xout (reg_color_grn), R1
xout (reg_color_blu), R1
call cg_wait_rdy
call cg_clr_screen
; Print greeting message
mov R1, greet_txt
call LCD_putsx
mov R1, greet_txt
call cg_puts
mov R1, crlf
call cg_puts_clr
xin R0, (ctrl_reg)
and R0, 0xCF
xout (ctrl_reg), R0
mov R0, 0
movc (round_cnt), R0
mov R0, 0x0F
xout (timer_reload+0), R0
mov R0, 0x27
xout (timer_reload+1), R0
mov R0, 0x00
xout (timer_reload+2), R0
main_loop: call do_clear
call write_uart_data
ML1: call do_write
call do_read
movc R0, (round_cnt)
inc R0
movc (round_cnt), R0
jmp ML1
; ----------------------------------------------------------
; SDRAM clear
; ----------------------------------------------------------
do_clear:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Clear message
mov R1, msg_txt0
call LCD_putsx
mov R1, msg_txt0
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
mov R0, 0
mov R1, 0
mov R2, 0
call AddrCnt_Init
; Fill SDR Buffer with zeros
mov R0, sdram_data
mov R15, 8
buf_clr_loop: movx (R0), 0
inc R0
dec R15
jnz buf_clr_loop
sdr_clear: mov R2, BURST_LEN
poll_clear_full:
xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_WRITE_DATA_FULL
jnz poll_clear_full
; Fill FIFO
mov R0, FIFO_CTRL_IS_WRITE
xout (sdram_reg), R0
sub R2, 2
jnz poll_clear_full
; Start SDR write
call wait_cmd_rdy
mov R0, SD_CMD_WRITE
xout (sdram_reg), R0
xin R0, (sdram_addr+0)
cmp R0, END_ADDR0
jne next_addr_c
xin R0, (sdram_addr+1)
cmp R0, END_ADDR1
jne next_addr_c
xin R0, (sdram_addr+2)
cmp R0, END_ADDR2
jeq clear_finished
; Advance address counter
next_addr_c: mov R0, BURST_LEN
call AddrCnt_Inc
jmp sdr_clear
clear_finished:
call AddrCnt_Disp
call delay1s
ret
; ----------------------------------------------------------
; SDRAM Write
; ----------------------------------------------------------
write_uart_data:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Clear message
mov R1, msg_txt3
call LCD_putsx
mov R1, msg_txt3
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
; mov R0, 0xF8 ; 800x600
; mov R1, 0x52 ; 800x600
; mov R2, 0x07 ; 800x600
pen_restart: mov R0, 0x00 ; 1280x1024
mov R1, 0x00 ; 1280x1024
mov R2, 0x00 ; 1280x1024
call AddrCnt_Init
call pen_init
chk_pen_off: xin R0, (btn_port)
and R0, 0x20
jnz chk_pen_off
mov R0, 1
chk_pen_on: xin R0, (btn_port)
and R0, 0x20
jz chk_pen_on
movc R0, (pen_rx_ptr_w)
sub R0, 5
cmp R0, pen_rx_buf+128
jlt set_rx_ptr
sub R0, 128
set_rx_ptr: movc (pen_rx_ptr_r), R0
; Fill SDR Buffer
get_pen: mov R1, pixel_buf
wls0: call pen_getchar
movc (R1), R0
inc R1
cmp R1, pixel_buf+8
jne wls0
; Start SDR write
xin R0, (sdram_addr+0)
push R0
xin R0, (sdram_addr+1)
push R0
xin R0, (sdram_addr+2)
push R0
mov R15, 64
write_sd_block: mov R2, BURST_LEN
mov R1, pixel_buf
copy_sdram: mov R3, sdram_data
copy_pixel: movc R0, (R1)
movx (R3), R0
inc R3
movx (R3), R0
inc R3
movx (R3), R0
inc R3
inc R1
cmp R3, sdram_data+6
jne copy_pixel
pwf: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_WRITE_DATA_FULL
jnz pwf
; Fill FIFO
mov R0, FIFO_CTRL_IS_WRITE
xout (sdram_reg), R0
sub R2, 2
jnz copy_sdram
call wait_cmd_rdy
mov R0, SD_CMD_WRITE
xout (sdram_reg), R0
; call AddrCnt_Disp
xin R0, (sdram_addr+1)
add R0, 0x05
xout (sdram_addr+1), R0
xin R0, (sdram_addr+2)
addc R0, 0x00
xout (sdram_addr+2), R0
dec R15
jnz write_sd_block
; Advance address counter
pop R0,
xout (sdram_addr+2), R0
pop R0
xout (sdram_addr+1), R0
pop R0
xout (sdram_addr+0), R0
xin R0, (sdram_addr+0)
cmp R0, 0xF8
jne next_addr
xin R0, (sdram_addr+1)
cmp R0, 0x04
jne next_addr
xin R0, (sdram_addr+2)
cmp R0, 0x00
jeq pen_restart
next_addr: mov R0, BURST_LEN
call AddrCnt_Inc
jmp get_pen
sdw_fin: call delay1s
ret
; ----------------------------------------------------------
; SDRAM Write
; ----------------------------------------------------------
do_write:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Write message
mov R1, msg_txt1
call LCD_putsx
mov R1, msg_txt1
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
mov R0, START_ADDR0
mov R1, START_ADDR1
mov R2, START_ADDR2
call AddrCnt_Init
movc R0, (round_cnt)
movc (block_cnt), R0
sdr_write: mov R2, BURST_LEN
; Fill SDR Buffer
sdr_burst_wr: movc R1, (block_cnt)
mov R0, sdram_data
mov R15, 8
write_loop: movx (R0), R1
inc R0
inc R1
dec R15
jnz write_loop
poll_write_full:
xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_WRITE_DATA_FULL
jnz poll_write_full
; Fill FIFO
mov R0, FIFO_CTRL_IS_WRITE
xout (sdram_reg), R0
movc R0, (block_cnt)
inc R0
movc (block_cnt), R0
sub R2, 2
jnz sdr_burst_wr
; Start SDR write
call wait_cmd_rdy
mov R0, SD_CMD_WRITE
xout (sdram_reg), R0
xin R0, (sdram_addr+0)
cmp R0, END_ADDR0
jne next_addr_w
xin R0, (sdram_addr+1)
cmp R0, END_ADDR1
jne next_addr_w
xin R0, (sdram_addr+2)
cmp R0, END_ADDR2
jeq write_finished
; Advance address counter
next_addr_w: mov R0, BURST_LEN
call AddrCnt_Inc
jmp sdr_write
write_finished: call AddrCnt_Disp
call delay1s
ret
; ----------------------------------------------------------
; SDRAM Verify
; ----------------------------------------------------------
do_read:
; Clear LCD
mov R0, LCD_CMD_CLEAR
call LCD_writecmd
; Print Read message
mov R1, msg_txt2
call LCD_putsx
mov R1, msg_txt2
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
; Set SDRAM address register to 0
mov R0, START_ADDR0
mov R1, START_ADDR1
mov R2, START_ADDR2
call AddrCnt_Init
movc R0, (round_cnt)
movc (block_cnt), R0
; flush_data
flush_data: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_READ_DATA_EMPTY
jnz sdr_read
mov R0, FIFO_CTRL_IS_READ
xout (sdram_reg), R0
jmp flush_data
sdr_read: ; Start SDR read
call wait_cmd_rdy
mov R0, SD_CMD_READ
xout (sdram_reg), R0
mov R3, BURST_LEN
; Wait last read
poll_read_fin: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_READ_DATA_EMPTY
jnz poll_read_fin
; Verify SDR Buffer
movc R1, (block_cnt)
mov R0, sdram_data
mov R15, 8
read_loop: movx R2, (R0)
cmp R2, R1
jne verify_error
inc R0
inc R1
dec R15
jnz read_loop
; Advance Read-FIFO
mov R0, FIFO_CTRL_IS_READ
xout (sdram_reg), R0
movc R0, (block_cnt)
inc R0
movc (block_cnt), R0
sub R3, 2
jnz poll_read_fin
xin R0, (sdram_addr+0)
cmp R0, END_ADDR0
jne next_addr_r
xin R0, (sdram_addr+1)
cmp R0, END_ADDR1
jne next_addr_r
xin R0, (sdram_addr+2)
cmp R0, END_ADDR2
jeq read_finished
; Advance address counter
next_addr_r: mov R0, BURST_LEN
call AddrCnt_Inc
jmp sdr_read
; ----------------------------------------------------------
wait_cmd_rdy: push R0
wait4cmd: xin R0, (sdram_reg)
xout (led_port), R0
and R0, FIFO_STAT_CMD_FULL
jnz wait4cmd
pop R0
ret
; ----------------------------------------------------------
read_finished:
no_error: mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R1, verify_ok
call LCD_putsx
mov R0, LCD_CMD_Z2
call LCD_writecmd
call print_addr
mov R1, verify_ok
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
jmp ende
verify_error: mov R0, LCD_CMD_CLEAR
call LCD_writecmd
mov R1, verify_nok
call LCD_putsx
call print_addr
call print_data
mov R1, verify_nok
call cg_clr_puts
mov R1, crlf
call cg_puts_clr
xin R0, (ctrl_reg)
or R0, 0x10
xout (ctrl_reg), R0
jmp ende
ende: call delay1s
ret
; -------------------------------------------------
AddrCnt_Init: xout (sdram_addr+0), R0
xout (sdram_addr+1), R1
xout (sdram_addr+2), R2
ret
; -------------------------------------------------
; Parameter
; R0: increment value
AddrCnt_Inc: push R1
push R2
push R3
xin R1, (sdram_addr+0)
xin R2, (sdram_addr+1)
xin R3, (sdram_addr+2)
add R1, R0
addc R2, 0
addc R3, 0
xout (sdram_addr+0), R1
xout (sdram_addr+1), R2
xout (sdram_addr+2), R3
pop R3
pop R2
pop R1
ret
; -------------------------------------------------
; Parameter
; R0: decrement value
AddrCnt_Dec: push R1
push R2
push R3
xin R1, (sdram_addr+0)
xin R2, (sdram_addr+1)
xin R3, (sdram_addr+2)
sub R1, R0
subc R2, 0
subc R3, 0
xout (sdram_addr+0), R1
xout (sdram_addr+1), R2
xout (sdram_addr+2), R3
pop R3
pop R2
pop R1
ret
; -------------------------------------------------
; Display Address counter
AddrCnt_Disp: mov R0, LCD_CMD_Z2
call LCD_writecmd
call print_addr
ret
; -------------------------------------------------
; PutHexByte
; R0 : Byte value
PutHexByte: push R1
call bin2hex
call LCD_writechar
mov R0, R1
call LCD_writechar
pop R1
ret
; -------------------------------------------------
print_addr: push R0
xin R0, (sdram_addr+2)
call PutHexByte
xin R0, (sdram_addr+1)
call PutHexByte
xin R0, (sdram_addr+0)
call PutHexByte
pop R0
ret
; -------------------------------------------------
; R1 : ptr to byte array
print_dword: push R0
add R1, 3
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
dec R1
movc R0, (R1)
call PutHexByte
pop R0
ret
; -------------------------------------------------
print_data: push R0
mov R0, LCD_CMD_Z2
call LCD_writecmd
movx R0, (sdram_data+7)
call PutHexByte
movx R0, (sdram_data+6)
call PutHexByte
movx R0, (sdram_data+5)
call PutHexByte
movx R0, (sdram_data+4)
call PutHexByte
movx R0, (sdram_data+3)
call PutHexByte
movx R0, (sdram_data+2)
call PutHexByte
movx R0, (sdram_data+1)
call PutHexByte
movx R0, (sdram_data+0)
call PutHexByte
pop R0
ret
; -------------------------------------------------
pen_init: push R0
mov R0, 0
movc (pen_enable), R0
call delay10ms
mov R0, pen_rx_buf
movc (pen_rx_ptr_r), R0
movc (pen_rx_ptr_w), R0
mov R0, PEN_TIMEOUT0
movc (pen_timeout+0), R0
mov R0, PEN_TIMEOUT1
movc (pen_timeout+1), R0
mov R0, 0
movc (pen_bit_cnt_w), R0
movc (pen_octet_w), R0
movc (pen_octet_r), R0
mov R0, 7
movc (pen_bit_cnt_r), R0
pop R0
ret
; -------------------------------------------------
; Params: none
; Return:
; R0 : received character
pen_getchar: push R1
push R2
push R3
movc R3, (pen_octet_r)
movc R1, (pen_rx_ptr_r)
movc R2, (pen_bit_cnt_r)
inc R2
cmp R2, 8
jne u_upd_r_ptr
mov R2, 0
pen_wait_rx: movc R0, (pen_rx_ptr_w)
cmp R0, R1
jeq pen_wait_rx
movc R3, (R1)
inc R1
cmp R1, pen_rx_buf+128
jne u_upd_r_ptr
mov R1, pen_rx_buf
u_upd_r_ptr: movc (pen_rx_ptr_r), R1
movc (pen_bit_cnt_r), R2
ex_pen_gc: mov R0, 0xFF
shl R3
jnc pen_is_zero
mov R0, 0x00
pen_is_zero: movc (pen_octet_r), R3
pop R3
pop R2
pop R1
ret
; -------------------------------------------------
include "../../../lib/jasm/utils.inc.jsm"
include "../../../lib/jasm/lcd.inc.jsm"
include "../../../lib/jasm/cg.inc.jsm"
include "../../../lib/jasm/delays.inc.jsm"
include "../../../lib/jasm/uart.inc.jsm"