1313; You should have received a copy of the GNU General Public License
1414; along with Programator. If not, see <https://www.gnu.org/licenses/>.
1515;
16- ; Copyright (c) 2022, 2024 Aleksander Mazur
16+ ; Copyright (c) 2022, 2024, 2025 Aleksander Mazur
1717;
1818; Funkcje pomocnicze, głównie do obsługi wejścia (poleceń)
1919
@@ -303,20 +303,25 @@ receive_hex_rec2:
303303 acall receive_hex_byte
304304 jc receive_hex_rec_error_H ; nie hex
305305 ; A = typ rekordu (0 - dane, 1 - koniec)
306+ mov R6 , A
307+ ; w R6 policzymy sobie sumę kontrolną
308+ add A , R7
309+ add A , R4
310+ add A , R5
311+ xch A , R6
306312 jz receive_hex_rec_payload
313+ cjne A , # 1 , receive_hex_rec_error_R
314+ receive_hex_rec_check_sum:
315+ ; wszystkie bajty odebrane, teraz powinna być suma kontrolna
316+ acall receive_hex_byte
317+ jc receive_hex_rec_error_H ; nie hex
318+ add A , R6
307319 setb C
308- dec A
309- jz ret7 ; A=0 i C=1 oznacza EOF
310- ; nieprawidłowy typ rekordu
311- mov A , # 'R'
320+ jz ret7 ; suma OK? to C=1 i A=0
321+ mov A , # 'S'
312322ret7:
313323 ret
314324receive_hex_rec_payload:
315- ; w R6 policzymy sobie sumę kontrolną
316- mov A , R7
317- add A , R4
318- add A , R5
319- mov R6 , A
320325 mov R0 , #input ; R0 = pozycja w buforze
321326 mov A , R7
322327 jz receive_hex_rec_checksum
@@ -329,14 +334,12 @@ receive_hex_rec_loop:
329334 inc R0
330335 djnz R3 , receive_hex_rec_loop
331336receive_hex_rec_checksum:
332- ; wszystkie bajty odebrane, teraz powinna być suma kontrolna
333- acall receive_hex_byte
334- jc receive_hex_rec_error_H ; nie hex
335- add A , R6
336- jnz receive_hex_rec_error_S
337+ acall receive_hex_rec_check_sum
338+ jnz ret9
339+ ; rekord wczytany poprawnie
337340 mov R0 , #input
338- receive_hex_rec_eof:
339341 clr C
342+ ret9:
340343 ret
341344receive_hex_rec_error_H:
342345 ; C=1
@@ -346,9 +349,9 @@ receive_hex_rec_error_L:
346349 setb C
347350 mov A , # 'L'
348351 ret
349- receive_hex_rec_error_S :
352+ receive_hex_rec_error_R :
350353 setb C
351- mov A , # 'S '
354+ mov A , # 'R '
352355 ret
353356
354357;-----------------------------------------------------------
@@ -379,14 +382,13 @@ load_hex_file:
379382 acall ensure_no_args
380383load_hex_file_loop:
381384 acall receive_hex_rec
382- jc load_hex_file_check
385+ jc load_hex_rec_check
383386 ; pod R0 jest R7 bajtów do zapisu pod adres R4:R5
384387 ; (adres z R4:R5 jest w dziedzinie specyficznej dla callbacka)
385388 mov A , R7
386389 jz load_hex_rec_empty ; zabezpieczenie przed rekordem o zerowej długości
387390 clr A
388391 acall jmp_dptr
389- load_hex_file_check:
390392 jz ret8
391393load_hex_file_error:
392394 ; w A jest znak ACK/NAK
@@ -395,6 +397,11 @@ load_hex_file_error:
395397load_hex_rec_empty:
396398 mov A , # 'G'
397399 sjmp load_hex_file_error
400+ load_hex_rec_check:
401+ ; C=1 i A=0 -> EOF; wypisujemy G i wychodzimy
402+ jnz load_hex_file_error
403+ mov A , # 'G'
404+ ajmp uart_send_char
398405
399406;-----------------------------------------------------------
400407; Dekoduje liczbę szesnastkową podaną w ASCII do rejestrów R2:R3.
0 commit comments