From 80697e12f89960bcf094a093d3c82d38da75c62d Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 22 Apr 2020 00:06:25 +0200 Subject: [PATCH] Added improved update script and .gitignore --- .build/rom_monitor.bin | Bin 2028 -> 0 bytes .build/rom_monitor.lst | 707 ----------------------------------------- .gitignore | 2 + upload.py | 50 +++ 4 files changed, 52 insertions(+), 707 deletions(-) delete mode 100644 .build/rom_monitor.bin delete mode 100644 .build/rom_monitor.lst create mode 100644 .gitignore create mode 100755 upload.py diff --git a/.build/rom_monitor.bin b/.build/rom_monitor.bin deleted file mode 100644 index c4a6ac5e9aefb6ea006c787332618eed80c08fef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2028 zcmah}TWAzl82;z7*>z&FgZ6?el{47~HO4eXW9$+)O-%H`OF^We6qL!%Np|Y)%sMlh z%~IWJA1tlDNU1_EFMX&j6nXd$cZBX@(?0tTdvK%Qkj6+2tKNU(sUs{c`Ld!NkYNLL{qdCE?2HX=-&6RGG6`?ihgp= zFU?dxh3VP3${%ojed9M0Ul#m4-rMi@`dwSPw{Gj%-n-+Ofx%rv!@ISJT0H>t^xg<9aLYt8W;p&2|6JBsO^x+_9kI)ZyTr@KwFclofFz*wHZmh{dWd$jtP}9 zp}h$wzVcJoy|cos^5?~=M6b(7F7 zsokPlt_!GIic=}H`bJ+t2B#ufv{D!P5S(PV)#Z-_B#UbGjEKzR%UL)- zv3$OS$7lfwK9#u}tU4`LPvJ3EPKe!DcVW09aDf}gh;Yf1iE zYfZ9R6myZvR|GjZ^)0^YkwTneQ$A`^@J56F^CRe8^YnkjQZ3S8%{7!1sUG!*Esr}a z!>w^I&FnEYW@b3^Y?iTggKaQ)%FODSjR^(~pk;RwYP9HamtaOdn|lOo-{8Pvw1agK za(hqD)*cdytbK9syxO+ShB<8Xj^X~)iwr`c{| zw=0ES`&K4Gy-latvh-O7t+Bzr^xhi-Lw`hlX&2_gQc;S!@ay?u|k?#xLC_{ z)7#G=$gHRrd5S^4bfgGIN@sZ|NIUqX23c;?9@o-uXc0h(1$%eRGZ!padz z8HxQ3m5*giU7q?t4#ulv@$v;(lBDwMvZUCOGVW`UCe+c+P=i)MAc=Q`@-bO^`l0ya zBE=8i7r(9DB_C9h3i@XumK<_QK&9`E`UBQKpO>4-hzHe^GptK|1mlm00`|E zK(B%WsazHSUJZXCzZSkOpAG*epTqxK;lJby_ or = hl (buffer address) - jp c,decimal_continue ;borrow means bc > hl - jp z,decimal_continue ;z means bc = hl - ld hl,(current_value) ;return if de < buffer address (no borrow) - scf ;get value back from RAM variable - ccf - ret ;return with carry clear, value in hl -decimal_continue: ld a,(bc) ;next char in string (right to left) - sub 030h ;ASCII value of zero char - jp m,decimal_error ;error if char value less than 030h - cp 00ah ;error if byte value > or = 10 decimal - jp p,decimal_error ;a reg now has value of decimal numeral - ld hl,(value_pointer) ;get value to add an put in de - ld e,(hl) ;little-endian (low byte in low memory) - inc hl - ld d,(hl) - inc hl ;hl now points to next value - ld (value_pointer),hl - ld hl,(current_value) ;get back current value -decimal_add: dec a ;add loop to increase total value - jp m,decimal_add_done ;end of multiplication - add hl,de - jp decimal_add -decimal_add_done: ld (current_value),hl - jp decimal_next_char -decimal_error: scf - ret - jp decimal_add -decimal_place_value: defw 1,10,100,1000,10000 -; -;Memory dump -;Displays a 256-byte block of memory in 16-byte rows. -;Called with address of start of block in HL -memory_dump: ld (current_location),hl ;store address of block to be displayed - ld a,000h - ld (byte_count),a ;initialize byte count - ld (line_count),a ;initialize line count - jp dump_new_line -dump_next_byte: ld hl,(current_location) ;get byte address from storage, - ld a,(hl) ;get byte to be converted to string - inc hl ;increment address and - ld (current_location),hl ;store back - ld hl,buffer ;location to store string - call byte_to_hex_string ;convert - ld hl,buffer ;display string - call write_string - ld a,(byte_count) ;next byte - inc a - jp z,dump_done ;stop when 256 bytes displayed - ld (byte_count),a ;not finished yet, store - ld a,(line_count) ;end of line (16 characters)? - cp 00fh ;yes, start new line - jp z,dump_new_line - inc a ;no, increment line count - ld (line_count),a - ld a,020h ;print space - call write_char - jp dump_next_byte ;continue -dump_new_line: ld a,000h ;reset line count to zero - ld (line_count),a - call write_newline - ld hl,(current_location) ;location of start of line - ld a,h ;high byte of address - ld hl, buffer - call byte_to_hex_string ;convert - ld hl,buffer - call write_string ;write high byte - ld hl,(current_location) - ld a,l ;low byte of address - ld hl, buffer - call byte_to_hex_string ;convert - ld hl,buffer - call write_string ;write low byte - ld a,020h ;space - call write_char - jp dump_next_byte ;now write 16 bytes -dump_done: ld a,000h - ld hl,buffer - ld (hl),a ;clear buffer of last string - call write_newline - ret -; -;Memory load -;Loads RAM memory with bytes entered as hex characters -;Called with address to start loading in HL -;Displays entered data in 16-byte rows. -memory_load: ld (current_location),hl - ld hl,data_entry_msg - call write_string - jp load_new_line -load_next_char: call get_char - cp 00dh ;return? - jp z,load_done ;yes, quit - ld (buffer),a - call get_char - cp 00dh ;return? - jp z,load_done ;yes, quit - ld (buffer+1),a - ld hl,buffer - call hex_to_byte - jp c,load_data_entry_error ;non-hex character - ld hl,(current_location) ;get byte address from storage, - ld (hl),a ;store byte - inc hl ;increment address and - ld (current_location),hl ;store back - ld a,(buffer) - call write_char - ld a,(buffer+1) - call write_char - ld a,(line_count) ;end of line (16 characters)? - cp 00fh ;yes, start new line - jp z,load_new_line - inc a ;no, increment line count - ld (line_count),a - ld a,020h ;print space - call write_char - jp load_next_char ;continue -load_new_line: ld a,000h ;reset line count to zero - ld (line_count),a - call write_newline - jp load_next_char ;continue -load_data_entry_error: call write_newline - ld hl,data_error_msg - call write_string - ret -load_done: call write_newline - ret -; -;Get one ASCII character from the serial port. -;Returns with char in A reg. No error checking. -get_char: in a,(3) ;get status - and 002h ;check RxRDY bit - jp z,get_char ;not ready, loop - in a,(2) ;get char - ret -; -;Subroutine to start a new line -write_newline: ld a,00dh ;ASCII carriage return character - call write_char - ld a,00ah ;new line (line feed) character - call write_char - ret -; -;Subroutine to read one disk sector (256 bytes) -;Address to place data passed in HL -;LBA bits 0 to 7 passed in C, bits 8 to 15 passed in B -;LBA bits 16 to 23 passed in E -disk_read: -rd_status_loop_1: in a,(0fh) ;check status - and 80h ;check BSY bit - jp nz,rd_status_loop_1 ;loop until not busy -rd_status_loop_2: in a,(0fh) ;check status - and 40h ;check DRDY bit - jp z,rd_status_loop_2 ;loop until ready - ld a,01h ;number of sectors = 1 - out (0ah),a ;sector count register - ld a,c - out (0bh),a ;lba bits 0 - 7 - ld a,b - out (0ch),a ;lba bits 8 - 15 - ld a,e - out (0dh),a ;lba bits 16 - 23 - ld a,11100000b ;LBA mode, select drive 0 - out (0eh),a ;drive/head register - ld a,20h ;Read sector command - out (0fh),a -rd_wait_for_DRQ_set: in a,(0fh) ;read status - and 08h ;DRQ bit - jp z,rd_wait_for_DRQ_set ;loop until bit set -rd_wait_for_BSY_clear: in a,(0fh) - and 80h - jp nz,rd_wait_for_BSY_clear - in a,(0fh) ;clear INTRQ -read_loop: in a,(08h) ;get data - ld (hl),a - inc hl - in a,(0fh) ;check status - and 08h ;DRQ bit - jp nz,read_loop ;loop until cleared - ret -; -;Subroutine to write one disk sector (256 bytes) -;Address of data to write to disk passed in HL -;LBA bits 0 to 7 passed in C, bits 8 to 15 passed in B -;LBA bits 16 to 23 passed in E -disk_write: -wr_status_loop_1: in a,(0fh) ;check status - and 80h ;check BSY bit - jp nz,wr_status_loop_1 ;loop until not busy -wr_status_loop_2: in a,(0fh) ;check status - and 40h ;check DRDY bit - jp z,wr_status_loop_2 ;loop until ready - ld a,01h ;number of sectors = 1 - out (0ah),a ;sector count register - ld a,c - out (0bh),a ;lba bits 0 - 7 - ld a,b - out (0ch),a ;lba bits 8 - 15 - ld a,e - out (0dh),a ;lba bits 16 - 23 - ld a,11100000b ;LBA mode, select drive 0 - out (0eh),a ;drive/head register - ld a,30h ;Write sector command - out (0fh),a -wr_wait_for_DRQ_set: in a,(0fh) ;read status - and 08h ;DRQ bit - jp z,wr_wait_for_DRQ_set ;loop until bit set -write_loop: ld a,(hl) - out (08h),a ;write data - inc hl - in a,(0fh) ;read status - and 08h ;check DRQ bit - jp nz,write_loop ;write until bit cleared -wr_wait_for_BSY_clear: in a,(0fh) - and 80h - jp nz,wr_wait_for_BSY_clear - in a,(0fh) ;clear INTRQ - ret -; -;Strings used in subroutines -length_entry_string: defm "Enter length of file to load (decimal): ",0 -dump_entry_string: defm "Enter no. of bytes to dump (decimal): ",0 -LBA_entry_string: defm "Enter LBA (decimal, 0 to 65535): ",0 -erase_char_string: defm 008h,01bh,"[K",000h ;ANSI sequence for backspace, erase to end of line. -address_entry_msg: defm "Enter 4-digit hex address (use upper-case A through F): ",0 -address_error_msg: defm 13,10,"Error: invalid hex character, try again: ",0 -data_entry_msg: defm "Enter hex bytes, hit return when finished.",13,10,0 -data_error_msg: defm "Error: invalid hex byte.",13,10,0 -decimal_error_msg: defm 13,10,"Error: invalid decimal number, try again: ",0 -; -;Simple monitor program for CPUville Z80 computer with serial interface. -monitor_cold_start: ld sp,ROM_monitor_stack - call initialize_port - ld hl,monitor_message - call write_string -monitor_warm_start: call write_newline ;routine program return here to avoid re-initialization of port - ld a,03eh ;cursor symbol - call write_char - ld hl,buffer - call get_line ;get monitor input string (command) - call write_newline - call parse ;interprets command, returns with address to jump to in HL - jp (hl) -; -;Parses an input line stored in buffer for available commands as described in parse table. -;Returns with address of jump to action for the command in HL -parse: ld bc,parse_table ;bc is pointer to parse_table -parse_start: ld a,(bc) ;get pointer to match string from parse table - ld e,a - inc bc - ld a,(bc) - ld d,a ;de will is pointer to strings for matching - ld a,(de) ;get first char from match string - or 000h ;zero? - jp z,parser_exit ;yes, exit no_match - ld hl,buffer ;no, parse input string -match_loop: cp (hl) ;compare buffer char with match string char - jp nz,no_match ;no match, go to next match string - or 000h ;end of strings (zero)? - jp z,parser_exit ;yes, matching string found - inc de ;match so far, point to next char in match string - ld a,(de) ;get next character from match string - inc hl ;and point to next char in input string - jp match_loop ;check for match -no_match: inc bc ;skip over jump target to - inc bc - inc bc ;get address of next matching string - jp parse_start -parser_exit: inc bc ;skip to address of jump for match - ld a,(bc) - ld l,a - inc bc - ld a,(bc) - ld h,a ;returns with jump address in hl - ret -; -;Actions to be taken on match -; -;Memory dump program -;Input 4-digit hexadecimal address -;Calls memory_dump subroutine -dump_jump: ld hl,dump_message ;Display greeting - call write_string - ld hl,address_entry_msg ;get ready to get address - call write_string - call address_entry ;returns with address in HL - call write_newline - call memory_dump - jp monitor_warm_start -; -;Hex loader, displays formatted input -load_jump: ld hl,load_message ;Display greeting - call write_string ;get address to load - ld hl,address_entry_msg ;get ready to get address - call write_string - call address_entry - call write_newline - call memory_load - jp monitor_warm_start -; -;Jump and run do the same thing: get an address and jump to it. -run_jump: ld hl,run_message ;Display greeting - call write_string - ld hl,address_entry_msg ;get ready to get address - call write_string - call address_entry - jp (hl) -; -;Help and ? do the same thing, display the available commands -help_jump: ld hl,help_message - call write_string - ld bc,parse_table ;table with pointers to command strings -help_loop: ld a,(bc) ;displays the strings for matching commands, - ld l,a ;getting the string addresses from the - inc bc ;parse table - ld a,(bc) ;pass address of string to hl through a reg - ld h,a - ld a,(hl) ;hl now points to start of match string - or 000h ;exit if no_match string - jp z,help_done - push bc ;write_char uses b register - ld a,020h ;space char - call write_char - pop bc - call write_string ;writes match string - inc bc ;pass over jump address in table - inc bc - inc bc - jp help_loop -help_done: jp monitor_warm_start -; -;Binary file load. Need both address to load and length of file -bload_jump: ld hl,bload_message - call write_string - ld hl,address_entry_msg - call write_string - call address_entry - call write_newline - push hl - ld hl,length_entry_string - call write_string - call decimal_entry - ld b,h - ld c,l - ld hl,bload_ready_message - call write_string - pop hl - call bload - jp monitor_warm_start -; -;Binary memory dump. Need address of start of dump and no. bytes -bdump_jump: ld hl,bdump_message - call write_string - ld hl,address_entry_msg - call write_string - call address_entry - call write_newline - push hl - ld hl,dump_entry_string - call write_string - call decimal_entry - ld b,h - ld c,l - ld hl,bdump_ready_message - call write_string - call get_char - pop hl - call bdump - jp monitor_warm_start -;Disk read. Need memory address to place data, LBA of sector to read -diskrd_jump: ld hl,diskrd_message - call write_string - ld hl,address_entry_msg - call write_string - call address_entry - call write_newline - push hl - ld hl,LBA_entry_string - call write_string - call decimal_entry - ld b,h - ld c,l - ld e,00h - pop hl - call disk_read - jp monitor_warm_start -diskwr_jump: ld hl,diskwr_message - call write_string - ld hl,address_entry_msg - call write_string - call address_entry - call write_newline - push hl - ld hl,LBA_entry_string - call write_string - call decimal_entry - ld b,h - ld c,l - ld e,00h - pop hl - call disk_write - jp monitor_warm_start -cpm_jump: ld hl,0800h - ld bc,0000h - ld e,00h - call disk_read - jp 0800h -;Prints message for no match to entered command -no_match_jump: ld hl,no_match_message - call write_string - ld hl, buffer - call write_string - jp monitor_warm_start -; -;Monitor data structures: -; -monitor_message: defm 13,10,"ROM ver. 8",13,10,0 -no_match_message: defm "? ",0 -help_message: defm "Commands implemented:",13,10,0 -dump_message: defm "Displays a 256-byte block of memory.",13,10,0 -load_message: defm "Enter hex bytes starting at memory location.",13,10,0 -run_message: defm "Will jump to (execute) program at address entered.",13,10,0 -bload_message: defm "Loads a binary file into memory.",13,10,0 -bload_ready_message: defm 13,10,"Ready to receive, start transfer.",0 -bdump_message: defm "Dumps binary data from memory to serial port.",13,10,0 -bdump_ready_message: defm 13,10,"Ready to send, hit any key to start.",0 -diskrd_message: defm "Reads one sector from disk to memory.",13,10,0 -diskwr_message: defm "Writes one sector from memory to disk.",13,10,0 -;Strings for matching: -dump_string: defm "dump",0 -load_string: defm "load",0 -jump_string: defm "jump",0 -run_string: defm "run",0 -question_string: defm "?",0 -help_string: defm "help",0 -bload_string: defm "bload",0 -bdump_string: defm "bdump",0 -diskrd_string: defm "diskrd",0 -diskwr_string: defm "diskwr",0 -cpm_string: defm "cpm",0 -no_match_string: defm 0,0 -;Table for matching strings to jumps -parse_table: defw dump_string,dump_jump,load_string,load_jump - defw jump_string,run_jump,run_string,run_jump - defw question_string,help_jump,help_string,help_jump - defw bload_string,bload_jump,bdump_string,bdump_jump - defw diskrd_string,diskrd_jump,diskwr_string,diskwr_jump - defw cpm_string,cpm_jump - defw no_match_string,no_match_jump - - - -total time: 0.0659 sec. -no errors diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a6ce7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.build/ +.env/ diff --git a/upload.py b/upload.py new file mode 100755 index 0000000..e3defa2 --- /dev/null +++ b/upload.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +import serial +import os +import sys + +def progressbar(it, prefix="", size=60, file=sys.stdout): + count = len(it) + def show(j): + x = int(size*j/count) + file.write("%s[%s%s] %i/%i\r" % (prefix, "#"*x, "."*(size-x), j, count)) + file.flush() + show(0) + for i, item in enumerate(it): + yield item + show(i+1) + file.write("\n") + file.flush() + +def main(): + if len(sys.argv) == 2: + # ser = serial.Serial("COM3", timeout=1, write_timeout=1) + ser = serial.Serial("/dev/ttyACM0", timeout=1, write_timeout=1) + if ser.is_open: + # Clear out any existing input + ser.write(b'\n') + ser.readline() + + # Send the upload command + ser.write(b'#u\n') + print(ser.readline()) + + path = sys.argv[1] + size = os.path.getsize(path) + ser.write([size & 0xFF]) + ser.write([(size >> 8) & 0xFF]) + i = 0 + with open(path, "rb") as f: + for i in progressbar(range(size), "Upload: ", 40): + ser.write(f.read(1)) + + print(ser.readline()) + ser.close() + + else: + print("Failed to open serial port") + else: + print("Please provide file to upload") + +if "__main__": + main()