Advertisement
Zeda

getCatalogElement

Aug 4th, 2015
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _ConvKeyToTok=4A02h
  2. ;_Get_Tok_Strng=4594h
  3. ;_CreateTempString=4324h
  4. _ExecuteNewProgram=4C3Ch
  5. _PutS=450Ah
  6. _RclAns=4AD7h
  7. _ConvOP1=4AEFh
  8. keyExtend=8446h
  9. OP1=8478h
  10. OP3=OP1+33
  11. ;_OP4ToOP1=4138h
  12. _SetXXXXOP2=4792h
  13. _OP2ToOP1=4156h
  14. _StoAns=4ABFh
  15.  
  16. #define bcall(x) rst 28h \ .dw x
  17. .db $BB,$6D
  18. .org $9D95
  19. SetUpCatalogElement:
  20.     bit 3,(iy+36h)
  21.     jr z,setuphook
  22.     ld hl,(8000h)
  23.     ld a,h
  24.     or l
  25.     jr z,directions
  26.     ld (tablestart),hl
  27.     ld de,(8002h)
  28.     sbc hl,de
  29.     ld (tablesize),hl
  30.     in a,(6)
  31.     ld (pagereturn),a
  32.     ld c,-1
  33. pagesearchloop:
  34.     inc c
  35.     ld a,c
  36.     out (6),a
  37.     ld (hl),a
  38.     add a,2
  39.     jr nz,pagesearchloop
  40.     inc hl
  41.     ld a,(hl)
  42.     dec hl
  43.     sub 9
  44.     jr nz,pagesearchloop
  45.     ld a,c
  46.     ld (pagebase),a
  47.    
  48.     ld hl,0
  49.     ld (8000h),hl
  50.     ld (8002h),hl
  51.     bcall(5047h)   ;disablehook
  52. ;    bcall(4F90h)   ;disablehook
  53.     ld hl,progname
  54.     ld a,6
  55.     bcall(_ExecuteNewProgram)
  56.     ret
  57. setuphook:
  58.     ld hl,hook
  59.     ld de,9872h
  60.     ld bc,hookend-hook
  61.     ld a,c
  62.     push de
  63.     ldir
  64.     pop hl
  65.     ld (8000h),bc
  66.     ld (8002h),bc
  67.     bcall(5044h)     ;enable catalog1 hook
  68. ;    bcall(4F8Dh)     ;enable catalog2 hook
  69. directions:
  70.     ld hl,help
  71.     bcall(_PutS)
  72.     ret
  73. hook:
  74.     .db 83h
  75.     cp 5
  76.     jr nz,$+5
  77.     ld (8000h),hl
  78.     cp 6
  79.     ret nz
  80.     ld (8002h),de
  81.     ret
  82. hookend:
  83. progname:
  84.   .db "CATELEM",0
  85.   .dw progend-progstart
  86. progstart:
  87.     .db $BB,$6D
  88.     bcall(_RclAns)
  89.     and $1F
  90.     ret nz
  91.     bcall(_ConvOP1)
  92. tablesize =$+1
  93.     ld hl,0
  94.     or d
  95.     jr z,returnsize
  96.     dec de
  97.     sla e
  98.     rl d
  99.     add hl,de
  100.     jr c,dne
  101. tablestart=$+1
  102.     ld hl,0
  103. pagebase=$+1
  104.     ld a,1
  105.     out (6),a
  106.     add hl,de
  107.     ld a,(hl)
  108. ;FF=>FE, FD=>0
  109.     cp $FD
  110.     jr nz,$+3
  111.     xor a
  112.     add a,1
  113.     sbc a,1
  114.     ld c,a
  115.     inc hl
  116.     ld a,(hl)
  117.     ld (keyExtend),a
  118.     jr z,$+3
  119.     ld a,c
  120.     bcall(_ConvKeyToTok)
  121. pagereturn=$+1
  122.     ld a,7
  123.     out (6),a
  124.     ld c,1
  125.     ld hl,OP3+1
  126.     ld (hl),e
  127.     inc d
  128.     dec d
  129.     jr z,$+5
  130.     dec l
  131.     ld (hl),d
  132.     inc c
  133. outstr:
  134.     ld b,0
  135.     push hl
  136.     push bc
  137.     ld a,7
  138.     sub c
  139.     ld c,a
  140.     push bc
  141.     bcall(4B52h)    ;AnsName
  142.     rst 10h
  143.     ld (hl),4
  144.     pop hl
  145.     push de
  146.     inc de    
  147.     inc de
  148.     ex de,hl
  149.     bcall(4357h)    ;delmem
  150.     pop hl
  151.     pop bc
  152.     pop de
  153.     ld (hl),c
  154.     inc hl
  155.     ld (hl),b
  156.     inc hl
  157.     ex de,hl
  158.     ldir
  159.     ret
  160. dne:
  161.     ld c,3
  162.     ld hl,s_dne
  163.     jr outstr
  164. returnsize:
  165.     sub l
  166.     ld l,a
  167.     sbc a,a
  168.     sub h
  169.     ld h,a
  170.     srl h
  171.     rr l
  172.     inc hl
  173.     bcall(_SetXXXXOP2)
  174.     bcall(_OP2ToOP1)
  175. stoans:
  176.     bcall(_StoAns)
  177.     ret
  178. s_dne=$-progstart+$9D93
  179. .db "DNE"
  180. progend:
  181. help:
  182.   .db "Open the catalog"
  183.   .db "Then run this   "
  184.   .db "program again.  ",0
  185. .echo "setup:",$-$9D95
  186. .echo "catelem:",progend-progstart-2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement