Skip to content

Commit

Permalink
Use a single macro for values. (#120)
Browse files Browse the repository at this point in the history
* Renamed functions to improve readability
* Update melody size and tag count to be a single macro
  • Loading branch information
damosvil authored Jun 19, 2023
1 parent 38cc961 commit cec1f50
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/Modules/Eeprom.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****

ESC_LAYOUT_SIZE EQU 48
MELODY_SIZE EQU 140


;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Read all eeprom parameters
Expand Down Expand Up @@ -88,7 +92,7 @@ read_eeprom_exit:
;**** **** **** **** **** **** **** **** **** **** **** **** ****
erase_and_store_all_in_eeprom:
clr IE_EA ; Disable interrupts
call read_tags
call read_esc_layout
call read_melody
call erase_flash ; Erase flash

Expand Down Expand Up @@ -127,7 +131,7 @@ write_eeprom_block2:
djnz Temp4, write_eeprom_block2

; Now write tags, melogy and signature
call write_tags
call write_esc_layout
call write_melody
call write_eeprom_signature
mov DPTR, #Eep_Dummy ; Set pointer to uncritical area
Expand Down Expand Up @@ -205,42 +209,43 @@ write_eeprom_signature:
ret

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; Read all tags from flash and store in temporary storage
; Read esc layout bytes from flash and store in temporary storage
;**** **** **** **** **** **** **** **** **** **** **** **** ****
read_tags:
mov Temp3, #48 ; Number of tags
read_esc_layout:
mov Temp3, #ESC_LAYOUT_SIZE ; Number of esc layout bytes
mov Temp2, #Temp_Storage ; Set RAM address
mov Temp1, #Bit_Access
mov DPTR, #Eep_ESC_Layout ; Set flash address
read_tag:
read_esc_layout_byte:
call read_eeprom_byte
mov A, Bit_Access
mov @Temp2, A ; Write to RAM
inc Temp2
inc DPTR
djnz Temp3, read_tag
djnz Temp3, read_esc_layout_byte
ret

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; Write all tags from temporary storage and store in flash
; Write all esc layout bytes from temporary storage and
; store them in flash
;**** **** **** **** **** **** **** **** **** **** **** **** ****
write_tags:
mov Temp3, #48 ; Number of tags
write_esc_layout:
mov Temp3, #ESC_LAYOUT_SIZE ; Number of esc layout bytes
mov Temp2, #Temp_Storage ; Set RAM address
mov DPTR, #Eep_ESC_Layout ; Set flash address
write_tag:
write_esc_layout_byte:
mov A, @Temp2 ; Read from RAM
call write_eeprom_byte_from_acc
inc Temp2
inc DPTR
djnz Temp3, write_tag
djnz Temp3, write_esc_layout_byte
ret

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; Read bytes from flash and store in external memory
;**** **** **** **** **** **** **** **** **** **** **** **** ****
read_melody:
mov Temp3, #140 ; Number of bytes
mov Temp3, #MELODY_SIZE ; Number of bytes
mov Temp2, #0 ; Set XRAM address
mov Temp1, #Bit_Access
mov DPTR, #Eep_Pgm_Beep_Melody ; Set flash address
Expand All @@ -257,7 +262,7 @@ read_melody_byte:
; Write bytes from external memory and store in flash
;**** **** **** **** **** **** **** **** **** **** **** **** ****
write_melody:
mov Temp3, #140 ; Number of bytes
mov Temp3, #MELODY_SIZE ; Number of bytes
mov Temp2, #0 ; Set XRAM address
mov DPTR, #Eep_Pgm_Beep_Melody ; Set flash address
write_melody_byte:
Expand Down

0 comments on commit cec1f50

Please sign in to comment.