📄 pm2_mp3.asm
字号:
inc dptr
acall dptrtor6r7
ajmp edit1
edit2: mov dptr,#edits2
ajmp pcstr_h
;---------------------------------------------------------;
dir:
mov dptr, #prompt9
acall pcstr_h
mov r0, #21
dir0a: acall space
djnz r0, dir0a
;mov dptr, #prompt9b
acall pcstr_h
mov dph, #(bmem >> 8)
dir1: acall find_h ;find the next program in memory
jc dir2
dir_end:ajmp newline ;we're done if no more found
dir2:
acall dspace
mov dpl, #32 ;print its name
acall pstr
mov dpl, #32 ;how long is the name
acall lenstr
mov a, #33
clr c
subb a, r0
mov r0, a
mov a, #' ' ;print the right # of spaces
dir3: acall cout
djnz r0, dir3
mov dpl, #0
acall phex16 ;print the memory location
mov r0, #6
mov a, #' '
dir4: acall cout
djnz r0, dir4
mov dpl, #4 ;now figure out what type it is
clr a
movc a, @a+dptr
mov r2, dph ;save this, we're inside a search
dir5: cjne a, #254, dir5b
mov dptr, #type1 ;it's an external command
sjmp dir7
dir5b: cjne a, #253, dir5c
dir5bb: mov dptr, #type4 ;it's a startup routine
sjmp dir7
dir5c: cjne a, #35, dir5d
mov dptr, #type2 ;it's an ordinary program
sjmp dir7
dir5d: cjne a, #249, dir5e
sjmp dir5bb
dir5e:
dir6: mov dptr, #type5 ;who knows what the hell it is
dir7: acall pcstr_h ;print out the type
mov dph, r2 ;go back and find the next one
acall newline
mov a, #(emem >> 8)
cjne a, dph, dir8 ;did we just print the last one?
ajmp dir_end
dir8: inc dph
mov a, dph
cjne a, #((emem+1) >> 8) & 255, dir1
ajmp dir_end
;type1=Ext Command
;type4=Startup
;type2=Program
;type5=???
;---------------------------------------------------------;
run:
acall newline2
mov r2, #255 ;first print the menu, count items
mov dptr, #bmem
dec dph
run2: inc dph
mov a, dph
cjne a, #((emem+1) >> 8) & 255, run2b
sjmp run3
run2b: acall find_h
jnc run3 ;have we found 'em all??
mov dpl, #4
clr a
movc a, @a+dptr
orl a, #00000011b
cpl a
jz run2 ;this one doesn't run... find next
acall dspace
inc r2
mov a, #'A' ;print the key to press
add a, r2
acall cout_sp
acall dash_sp
mov dpl, #32
acall pstr ;and the command name
acall newline
ajmp run2 ;and continue doing this
run3: cjne r2, #255, run4 ;are there any to run??
mov dptr, #prompt5
ajmp pcstr_h
run4: mov dptr, #prompt3 ;ask the big question!
acall pcstr_h
mov a, #'A'
acall cout
acall dash
mov a, #'A' ;such user friendliness...
add a, r2 ;even tell 'em the choices
acall cout
mov dptr, #prompt4
acall pcstr_h
acall cin_filter_h
cjne a, #27, run4aa ;they they hit <ESC>
ajmp newline
run4aa: mov r3, a
mov a, #31
clr c
subb a, r2
mov a, r3
jc run4a
acall upper
run4a: acall cout
mov r3, a
acall newline
;check to see if it's under 32, if so convert to uppercase
mov a, r3
add a, #(256 - 'A')
jnc run4 ;if they typed less than 'A'
mov r3, a ;R3 has the number they typed
mov a, r2 ;A=R2 has the maximum number
clr c
subb a, r3
jc run4 ;if they typed over the max
inc r3
mov dptr, #bmem
dec dph
run5: inc dph
mov a, dph
cjne a, #((emem+1) >> 8) & 255, run5b
sjmp run8
run5b: acall find_h
jnc run8 ;Shouldn't ever do this jump!
mov dpl, #4
clr a
movc a, @a+dptr
orl a, #00000011b
cpl a
jz run5 ;this one doesn't run... find next
djnz r3, run5 ;count til we find the one they want
acall newline
mov dpl, #64
ajmp jump_doit
run8: ret
;---------------------------------------------------------;
help:
mov dptr, #help1txt
acall pcstr_h
mov r4, #help_key
mov dptr, #help_cmd
acall help2
mov r4, #dir_key
;mov dptr, #dir_cmd
acall help2
mov r4, #run_key
;mov dptr, #run_cmd
acall help2
mov r4, #dnld_key
;mov dptr, #dnld_cmd
acall help2
mov r4, #upld_key
;mov dptr, #upld_cmd
acall help2
mov r4, #nloc_key
;mov dptr, #nloc_cmd
acall help2
mov r4, #jump_key
;mov dptr, #jump_cmd
acall help2
mov r4, #dump_key
;mov dptr, #dump_cmd
acall help2
mov r4, #intm_key
;mov dptr, #intm_cmd
acall help2
mov r4, #edit_key
;mov dptr, #edit_cmd
acall help2
mov r4, #clrm_key
;mov dptr, #clrm_cmd
acall help2
mov r4, #erfr_key
;mov dptr, #erfr_cmd
acall help2
mov dptr, #help2txt
acall pcstr_h
mov dptr, #bmem
help3: acall find_h
jnc help4
mov dpl, #4
clr a
movc a,@a+dptr
cjne a, #254, help3a ;only FE is an ext command
acall dspace
inc dpl
clr a
movc a,@a+dptr
acall cout
acall dash_sp
mov dpl, #32
acall pstr
acall newline
help3a: inc dph
mov a, dph
cjne a, #((emem+1) >> 8) & 255, help3
help4:
ajmp newline
help2: ;print 11 standard lines
acall dspace ;given key in R4 and name in dptr
mov a, r4
acall cout
acall dash_sp
acall pcstr_h
ajmp newline
;---------------------------------------------------------;
upld:
acall get_mem
;assume we've got the beginning address in r3/r2
;and the final address in r5/r4 (r4=lsb)...
;print out what we'll be doing
mov dptr, #uplds3
acall pcstr_h
mov a, r3
acall phex
mov a, r2
acall phex
;mov dptr, #uplds4
acall pcstr_h
mov a, r5
acall phex
mov a, r4
acall phex
acall newline
;need to adjust end location by 1...
mov dph, r5
mov dpl, r4
inc dptr
mov r4, dpl
mov r5, dph
mov dptr, #prompt7
acall pcstr_h
acall cin
cjne a, #27, upld2e
ajmp abort_it
upld2e: acall newline
mov dpl, r2
mov dph, r3
upld3: mov a, r4 ;how many more bytes to output??
clr c
subb a, dpl
mov r2, a
mov a, r5
subb a, dph
jnz upld4 ;if >256 left, then do next 16
mov a, r2
jz upld7 ;if we're all done
anl a, #11110000b
jnz upld4 ;if >= 16 left, then do next 16
sjmp upld5 ;otherwise just finish it off
upld4: mov r2, #16
upld5: mov a, #':' ;begin the line
acall cout
mov a, r2
acall phex ;output # of data bytes
acall phex16 ;output memory location
mov a, dph
add a, dpl
add a, r2
mov r3, a ;r3 will become checksum
clr a
acall phex ;output 00 code for data
upld6: clr a
movc a, @a+dptr
acall phex ;output each byte
add a, r3
mov r3, a
inc dptr
djnz r2, upld6 ;do however many bytes we need
mov a, r3
cpl a
inc a
acall phex ;and finally the checksum
acall newline
acall line_dly
acall esc
jnc upld3 ;keep working if no esc pressed
sjmp abort_it
upld7: mov a, #':'
acall cout
clr a
acall phex
acall phex
acall phex
inc a
acall phex
mov a, #255
acall phex
upld8: ajmp newline2
line_dly: ;a brief delay between line while uploading, so the
;receiving host can be slow (i.e. most windows software)
mov a, r0
push acc
mov r0, #line_delay*2
line_d2:mov a, th0 ;get baud rate const
line_d3:inc a
nop
nop
jnz line_d3
djnz r0, line_d2
pop acc
mov r0, a
ret
;---------------------------------------------------------;
get_mem: ;this thing gets the begin and end locations for
;a few commands. If an esc or enter w/ no input,
;it pops it's own return and returns to the menu
;(nasty programming, but we need tight code for 4k rom)
acall newline2
mov dptr, #beg_str
acall pcstr_h
acall ghex16
jc pop_it
jb psw.5, pop_it
push dph
push dpl
acall newline
mov dptr, #end_str
acall pcstr_h
acall ghex16
mov r5, dph
mov r4, dpl
pop acc
mov r2, a
pop acc
mov r3, a
jc pop_it
jb psw.5, pop_it
ajmp newline
pop_it: pop acc
pop acc
abort_it:
acall newline
abort2: mov dptr, #abort
ajmp pcstr_h
clrm:
acall get_mem
mov dptr, #sure
acall pcstr_h
acall cin_filter_h
acall upper
cjne a, #'Y', abort_it
acall newline2
;now we actually do it
clrm2: mov dph, r3
mov dpl, r2
clrm3: clr a
lcall smart_wr
mov a, r5
cjne a, dph, clrm4
mov a, r4
cjne a, dpl, clrm4
ret
clrm4: inc dptr
sjmp clrm3
;---------------------------------------------------------;
nloc:
mov dptr, #prompt6
acall pcstr_h
acall ghex16
jc abort2
jb psw.5, abort2
acall dptrtor6r7
ajmp newline2
;---------------------------------------------------------;
erfr:
acall newline2
mov dptr, #erfr_cmd
acall pcstr_h
mov a, #','
acall cout_sp
mov dptr, #sure
acall pcstr_h
acall cin_filter_h
acall upper
cjne a, #'Y', abort_it
acall newline2
lcall erall
mov dptr, #erfr_ok
jnc erfr_end
mov dptr, #erfr_err
erfr_end:
ajmp pcstr_h
;---------------------------------------------------------;
intm: acall newline
mov r0, #0
intm2: acall newline
cjne r0, #0x80, intm3
ajmp newline
intm3: mov a, r0
acall phex
mov a, #':'
acall cout
intm4: acall space
mov a, @r0
acall phex
inc r0
mov a, r0
anl a, #00001111b
jnz intm4
sjmp intm2
;**************************************************************
;**************************************************************
;***** *****
;***** 2k page boundry is somewhere near here *****
;***** (no ajmp or acall past this point) *****
;***** *****
;**************************************************************
;**************************************************************
;---------------------------------------------------------;
; ;
; Subroutines for memory managment and non-serial I/O ;
; ;
;---------------------------------------------------------;
; poll the flash rom using it's toggle bit feature
; on D6... and wait until the flash rom is not busy
; dptr must be initialized with the address to read
flash_wait:
push b
clr a
movc a, @a+dptr
flwt2: mov b, a
inc r5
clr a
movc a, @a+dptr
cjne a, b, flwt2
pop b
push dph
push dpl
mov dptr, #dram_enable
clr a
movx @dptr, a
pop dpl
pop dph
ret
;send the flash enable codes
flash_en:
mov dptr, #dram_disable
clr a
movx @dptr, a
flash_en2:
mov dptr, #flash_en1_addr
mov a, #flash_en1_data
movx @dptr, a
mov dptr, #flash_en2_addr
mov a, #flash_en2_data
movx @dptr, a
ret
;a routine that writes ACC to into flash memory at DPTR
; C is set if error occurs, C is clear if it worked
prgm: xch a, r0
push acc
push dpl
push dph
lcall flash_en ;do first step, enable writing
mov dptr, #flash_wr_addr
mov a, #flash_wr_data
movx @dptr, a ;send flash write command
pop dph
pop dpl
mov a, r0
movx @dptr, a ;write the data
lcall flash_wait ;wait until it's done
clr a
movc a, @a+dptr ;read it back
clr c
xrl a, r0
jz prgmend ;check if data written ok
setb c
prgmend:pop acc
xch a, r0
ret
;send a custom erase command. This is used by erall,
;and it's intended to be callable from the flash memory
;so that custom block erase code can be implemented
erblock:
push acc
push dpl
push dph
lcall flash_en ;send flash enable stuff
mov dptr, #flash_er1_addr
mov a, #flash_er1_data
movx @dptr, a ;send erase enable
lcall flash_en2 ;send flash enable stuff
pop dph
pop dpl
pop acc
movx @dptr, a ;send erase command
sjmp flash_wait
; erase the entire flash rom
; C=1 if failure, C=0 if ok
erall:
mov dptr, #flash_er2_addr
mov a, #flash_er2_data
acall erblock ;use erblock to send erase all
mov dptr, #bflash
erall2: clr a
movc a, @a+dptr ;read back flash memory
cpl a
jnz erall_err ;check if it's really erased
inc dptr
mov a, #((eflash+1) & 255)
cjne a, dpl, erall2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -