Skip to content

Commit

Permalink
Default address used with uart1, when none given in ihex file
Browse files Browse the repository at this point in the history
  • Loading branch information
envenomator committed Jul 10, 2023
1 parent b9540ee commit 7703093
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
53 changes: 43 additions & 10 deletions src/hxload.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,30 @@
XDEF _hxload_vdp
XDEF _startaddress
XDEF _endaddress
XDEF _datarecords
XDEF _defaultAddressUsed
LOAD_HLU_DEFAULT .EQU 04h ; 0x040000 default load address

_hxload_uart1:
PUSH DE
PUSH HL
PUSH BC

LD DE,0
LD (_datarecords), DE ; clear number of data records
LD A, 1
LD (_defaultAddressUsed), A

LD A, LOAD_HLU_DEFAULT
LD (hexload_address + 2),A ; store HLU
XOR A,A
LD (hexload_error),A ; clear error counter
LD A, 1
LD (firstwrite),A ; firstwrite = true
LD (hexload_address + 1),A ; clear address[15:0] - this will be loaded from record type 0
LD (hexload_address),A
LD HL, hexload_address
LD HL,(HL) ; load assembled address from memory into HL as a pointer
LD (_startaddress),HL ; store first address

hxline:
CALL _uart1_getch
Expand Down Expand Up @@ -65,18 +77,32 @@ hex_address:
LD (hexload_address),A
LD HL, hexload_address
LD HL,(HL) ; load assembled address from memory into HL as a pointer
ld A,(firstwrite) ; is this the first address we write to?
CP A,1
JR NZ, $F ; if not, skip storing the first address
XOR A,A ; firstwrite = false
LD (firstwrite),A
LD (_startaddress),HL ; store first address

PUSH BC
PUSH HL
PUSH DE
LD BC, HL ; temp pointer in BC
LD HL, (_datarecords)
LD DE, 0 ; compare HL,0
OR A ; compare HL,0
SBC HL,DE ; compare HL,0
ADD HL,DE ; compare HL,0
JR NZ, $F
LD HL, BC ; restore temp pointer
LD (_startaddress), HL ; no data record received; record start address
XOR A,A
LD (_defaultAddressUsed), A; using this address record, not using default
$$:
POP DE
POP HL
POP BC

CALL getbyte ; load checksum
LD A,E
OR A
JR NZ, hexckerr ; checksum error on this line
JR hxline

hexdata:
CALL getbyte
LD (HL),A
Expand All @@ -88,6 +114,11 @@ hexdata:
OR A ; sum of all data incl checksum should be zero
JR NZ, hexckerr ; checksum error on this line
LD (_endaddress), HL ; store end address
PUSH HL
LD HL, (_datarecords)
INC HL ; increase number of datarecords
LD (_datarecords), HL
POP HL
JR hxline
hexckerr:
LD A,(hexload_error)
Expand Down Expand Up @@ -246,4 +277,6 @@ hexload_address DS 3 ; 24bit address
hexload_error DS 1 ; error counter
firstwrite DS 1 ; boolean
_startaddress DS 3 ; first address written to
_endaddress DS 3 ; last address written to
_endaddress DS 3 ; last address written to
_datarecords DS 3 ; number of data records read
_defaultAddressUsed DS 1 ; boolean
10 changes: 9 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ extern VOID uart1_handler(void);
// external variables
extern volatile UINT24 startaddress;
extern volatile UINT24 endaddress;
extern volatile UINT24 datarecords;
extern volatile UINT8 defaultAddressUsed;

// single VDP function needed
UINT8 vdp_cursorGetXpos(void);
Expand Down Expand Up @@ -92,7 +94,13 @@ void handle_hexload_uart1(UINT24 baudrate)
// Only feedback during transfer - we have no time to output to VDP or even UART1 between received bytes
printf("Receiving Intel HEX records - UART1:%d 8N1\r\n",baudrate);
c = hxload_uart1();
if(c == 0) printf("OK\r\n");
if(c == 0) {
printf("%d datarecords\r\n",datarecords);
printf("Start address 0x%06X",startaddress);
if(defaultAddressUsed) printf(" (default)\r\n");
else printf("\r\n");
printf("OK\r\n");
}
else printf("%d error(s)\r\n",c);

// close UART1, so no more interrupts will trigger before removal of handler
Expand Down

0 comments on commit 7703093

Please sign in to comment.