From e7b042efdc9b4b58b7f898b7b9334e2ae7c09e8d Mon Sep 17 00:00:00 2001 From: jonnosan Date: Sun, 17 Jul 2011 08:14:08 +0000 Subject: [PATCH] allow flashing of MK3 EEPROM git-svn-id: http://svn.code.sf.net/p/netboot65/code@319 93682198-c243-4bdb-bd91-e943c89aac3b --- client/wiznet/Makefile | 13 +- client/wiznet/wizboot.s | 25 ++- client/wiznet/wizflashheader.s | 289 +++++++++++++++++++++++++++++++++ client/wiznet/wiztest.s | 125 ++++++++++++-- 4 files changed, 434 insertions(+), 18 deletions(-) create mode 100644 client/wiznet/wizflashheader.s diff --git a/client/wiznet/Makefile b/client/wiznet/Makefile index ecc6925..ca00765 100644 --- a/client/wiznet/Makefile +++ b/client/wiznet/Makefile @@ -47,6 +47,9 @@ wizboot.bin: wizboot.o $(IP65WIZNETLIB) $(C64WIZNETLIB) $(INCFILES) ../cfg/c64_8 wizboot.prg: wizboot.bin cartheader.prg cat cartheader.prg wizboot.bin > $@ +wizflash.prg: wizboot.bin wizflashheader.prg + cat wizflashheader.prg wizboot.bin > $@ + telnetd.o: ../carts/telnetd.s $(INCFILES) timestamp.rb $(AS) $(AFLAGS) ../carts/telnetd.s -o telnetd.o @@ -64,8 +67,11 @@ wizbobcart.bin: wizbobcart.o $(IP65WIZNETLIB) $(C64WIZNETLIB) $(INCFILES) wizbob wizbobcart.prg: wizbobcart.bin cartheader.prg cat cartheader.prg wizbobcart.bin > $@ -wiztest.d64: wiztest.prg - ripxplore.rb -I CbmDos -a wiztest.prg $@ +wiztest.d64: wiztest.prg wizboot.prg wizflash.prg + ripxplore.rb -I CbmDos $@ + ripxplore.rb -a wizboot.prg $@ + ripxplore.rb -a wiztest.prg $@ + ripxplore.rb -a wizflash.prg $@ clean: rm -f *.o *.bin *.map *.prg *.pg2 *.dsk *.d64 @@ -87,4 +93,5 @@ bootc64.prg: # cp wizbobcart.prg ../../server/boot/bootc64.prg # cp telnetd.prg ../../server/boot/bootc64.prg # cp wizboot2.prg ../../server/boot/bootc64.prg - cp wiztest.prg ../../server/boot/bootc64.prg \ No newline at end of file + cp wiztest.prg ../../server/boot/bootc64.prg +# cp wizflash.prg ../../server/boot/bootc64.prg \ No newline at end of file diff --git a/client/wiznet/wizboot.s b/client/wiznet/wizboot.s index 068be16..e16c358 100644 --- a/client/wiznet/wizboot.s +++ b/client/wiznet/wizboot.s @@ -72,7 +72,6 @@ call_downloaded_prg: .code - cold_init: ;first let the kernal do a normal startup @@ -82,6 +81,30 @@ cold_init: jsr $fd15 ;set vectors for KERNAL jsr $ff5B ;init. VIC cli ;KERNAL init. finished + + + ;do the 'secret knock' to disable writes to the EEPROM + + lda #$55 + sta $9c55 + lda #$aa + sta $83aa + lda #$05 + sta $9c55 + +@poll_loop: + lda $8000 + cmp $8000 + bne @poll_loop + + ;copy ourselves to the C64 RAM + ;so if we go into 'SHUTUP' mode, we keep executing from the same address, in C64 RAM + ldax #$8000 + stax copy_src + stax copy_dest + ldax #$2000 + jsr copymem + warm_init: diff --git a/client/wiznet/wizflashheader.s b/client/wiznet/wizflashheader.s new file mode 100644 index 0000000..5214156 --- /dev/null +++ b/client/wiznet/wizflashheader.s @@ -0,0 +1,289 @@ + +.include "../inc/common.i" +print_a = $ffd2 + + + +.zeropage +cart_data_ptr: .res 2 +eeprom_ptr: .res 2 +pptr: .res 2 + +.segment "STARTUP" ;this is what gets put at the start of the file on the C64 + +.word basicstub ; load address + +basicstub: + .word @nextline + .word 2003 + .byte $9e + .byte <(((init / 1000) .mod 10) + $30) + .byte <(((init / 100 ) .mod 10) + $30) + .byte <(((init / 10 ) .mod 10) + $30) + .byte <(((init ) .mod 10) + $30) + .byte 0 +@nextline: + .word 0 + +init: + + ldax #banner + jsr print + cli + + ldax #$8000 + stax eeprom_ptr + + ;set up access to READ/WRITE external ROM + + lda #$37 + sta $01 + sta $de02 ;leave 'shut up' mode + sta $de08 ;enable ROM + sta $de0a ;set banking bit 0 + sta $de0c ;set banking bit 1 + + lda $d011 + sta old_d011 + and #$ef ;turn off bit 4 + sta $d011 + jsr turn_off_write_protect + + ldax #cart_data + stax cart_data_ptr + ldax #$8000 + stax eeprom_ptr + +@copy_64_bytes: +; lda cart_data_ptr+1 +; jsr print_hex +; lda cart_data_ptr +; jsr print_hex +; lda eeprom_ptr+1 +; jsr print_hex +; lda eeprom_ptr +; jsr print_hex + inc $d020 + + ldy #0 +@copy_1_byte: + lda (cart_data_ptr),y + sta (eeprom_ptr),y + iny + cpy #64 + bne @copy_1_byte + jsr poll_till_stable + + clc + tya + adc eeprom_ptr + sta eeprom_ptr + bcc :+ + inc eeprom_ptr+1 +: + clc + tya + adc cart_data_ptr + sta cart_data_ptr + bcc :+ + inc cart_data_ptr+1 +: + + lda eeprom_ptr+1 + cmp #$A0 + bne @copy_64_bytes + +;now validate the data + ldax #cart_data + stax cart_data_ptr + ldax #$8000 + stax eeprom_ptr + ldy #0 +@compare_loop: + lda (cart_data_ptr),y + cmp (eeprom_ptr),y + bne @validation_error + iny + bne @compare_loop + inc cart_data_ptr+1 + inc eeprom_ptr+1 + lda eeprom_ptr+1 + cmp #$A0 + bne @compare_loop + ldax #ok + jsr print + ldax #$8000 + stax eeprom_ptr + + jsr turn_on_write_protect + + jmp @exit_to_basic + +@validation_error: + sty error_offset + + ldax #validation_error + jsr print + lda eeprom_ptr+1 + jsr print_hex + lda eeprom_ptr + jsr print_hex + ldax #offset + jsr print + lda error_offset + jsr print_hex + jsr print_cr + + + ldax #wr + jsr print + lda #0 + sta byte_ptr +@wr_loop: + ldy byte_ptr + lda (cart_data_ptr),y + jsr print_hex + + lda byte_ptr + cmp error_offset + beq :+ + inc byte_ptr + bne @wr_loop +: + jsr print_cr + + ldax #rd + jsr print + lda #0 + sta byte_ptr +@rd_loop: + ldy byte_ptr + lda (eeprom_ptr),y + jsr print_hex + lda byte_ptr + cmp error_offset + beq :+ + inc byte_ptr + bne @rd_loop +: + jsr print_cr + +;if there is an error somewhere in the eeprom, but we have a valid 'CBM80' header bad things can happen +;so overwrite the signature bytes + lda #$FF + sta $8004 + sta $8005 + sta $8006 + sta $8007 + sta $8008 + +@exit_to_basic: + sei + lda old_d011 + sta $d011 + rts + +turn_off_write_protect: + ;do the 'secret knock' to enable writes + lda #$55 + sta $9c55 + lda #$aa + sta $83aa + lda #$01 + sta $9c55 + lda #$55 + sta $9c55 + lda #$aa + sta $83aa + lda #$04 + sta $9c55 + jmp poll_till_stable + +turn_on_write_protect: + ;do the 'secret knock' to disable writes + + lda #$55 + sta $9c55 + lda #$aa + sta $83aa + lda #$05 + sta $9c55 + +poll_till_stable: + ldax eeprom_ptr + stax @offset_1+1 + stax @offset_2+1 +@poll_loop: +@offset_1: + lda $8000 ;address will get overwritten +@offset_2: + cmp $8000 ;address will get overwritten + bne poll_till_stable + +@done: + rts + + +print_cr: + lda #13 + jmp print_a + +print: + sta pptr + stx pptr + 1 + +@print_loop: + ldy #0 + lda (pptr),y + beq @done_print + jsr print_a + inc pptr + bne @print_loop + inc pptr+1 + bne @print_loop ;if we ever get to $ffff, we've probably gone far enough ;-) +@done_print: + rts + +print_hex: + pha + pha + lsr + lsr + lsr + lsr + tax + lda hexdigits,x + jsr print_a + pla + and #$0F + tax + lda hexdigits,x + jsr print_a + pla + rts + +.rodata +hexdigits: +.byte "0123456789ABCDEF" + +banner: +.byte 147 ;cls +.byte 142 ;upper case +.byte 13," RR-NET MK3 FLASHER V0.02" +.include "timestamp.i" +.byte 13 +.byte 0 +ok: .byte 13,"OK",13,0 +validation_error: +.byte 13,"VALIDATION ERROR : $",0 +offset: .byte " OFFSET : $",0 + +rd: .byte "RD :",0 +wr: .byte "WR :",0 +.bss +cart_data: ;this should point to where the cart data gets appended. + .res $2000 + +error_offset: .res 1 +byte_ptr: .res 1 +old_d011: .res 1 diff --git a/client/wiznet/wiztest.s b/client/wiznet/wiztest.s index 2ac58a5..9bc224c 100644 --- a/client/wiznet/wiztest.s +++ b/client/wiznet/wiztest.s @@ -70,11 +70,36 @@ init: ldax #banner jsr print + + lda #0 + sta clockport_mode + lda $de01 + and #$fe ;turn off clockport + sta $de01 + + lda #$80 ;reset + sta WIZNET_MODE_REG + lda WIZNET_MODE_REG + bne @try_clockport + ;writing a byte to the MODE register with bit 7 set should reset. + ;after a reset, mode register is zero + ;therefore, if there is a real W5100 at the specified address, + ;we should be able to write a $80 and read back a $00 + + lda #$13 ;set indirect mode, with autoinc, no auto PING + sta WIZNET_MODE_REG + lda WIZNET_MODE_REG + cmp #$13 + beq @w5100_found +@try_clockport: + inc clockport_mode + ;now try with clockport on lda $de01 ora #1 ;turn on clockport sta $de01 + lda #$80 ;reset sta WIZNET_MODE_REG lda WIZNET_MODE_REG @@ -102,6 +127,9 @@ init: bne @error ;make sure if we write to mode register without bit 7 set, ;the value persists. + + +@w5100_found: ldax #w5100_found jsr print @@ -109,6 +137,14 @@ init: jsr print_hex lda #