Geekboy

Untitled

Feb 9th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Doors CS BASIC Libraries
  2. ;================================
  3. ;dbfStringWidth:            COMPLETE
  4. ;dbfPxScan:                 COMPLETE
  5. ;dbfHometoGraph:            COMPLETE
  6. ;dbfUsedPicList:            COMPLETE
  7. ;dbfArcUnarcPic:            COMPLETE
  8. ;dbfDCSLibVersion:          COMPLETE
  9. ;dbfSimpleGUIMouse:         COMPLETE
  10. ;dbfPushGUIStack:           COMPLETE
  11. ;dbfPopGUIStack:            COMPLETE
  12. ;dbfOpenGUIStack:           COMPLETE
  13. ;dbfCloseGUIStack:          COMPLETE
  14. ;dbfRenderGUIStack:         COMPLETE
  15. ;dbfGUIMouse:               COMPLETE
  16. ;dbfMenu:                   COMPLETE
  17. ;dbfCn2BASICSend:           INCOMPLETE
  18. ;dbfCn2BASICGet:            INCOMPLETE
  19. ;dbfCn2BASICStop:           Mostly Complete
  20. ;================================
  21. dbfStringWidth:
  22.     ld hl,sc1
  23.     call getsourcestring
  24.     ld de,0
  25.     jp z,dbfStringWidth_Finish  ;zero-length string
  26. dbfStringWidthLoopOuter:
  27.     push hl
  28.         push bc
  29.             push de
  30.                 bcall(_Get_Tok_Strng)
  31.                 ld hl,Op3
  32.                 pop de
  33. dbfStringWidthLoopInner:
  34.             push hl
  35.                 push bc
  36.                     ld a,(hl)
  37.                     push de
  38.                         bcall(_GetVarWidth)
  39.                         ld l,d
  40.                         ld h,0
  41.                         pop de
  42.                     add hl,de
  43.                     ex de,hl
  44.                     pop bc
  45.                 pop hl
  46.             inc hl
  47.             dec bc
  48.             ld a,b
  49.             or c
  50.             jr nz,dbfStringWidthLoopInner
  51.             pop bc
  52.         pop hl
  53.     ld a,(hl)
  54.     inc hl
  55.     dec bc
  56.     bcall(_IsA2ByteTok)
  57.     jr nz,dbfStringWidthLoopOuter2
  58.     inc hl
  59.     dec bc
  60. dbfStringWidthLoopOuter2:
  61.     ld a,b
  62.     or c
  63.     jr nz,dbfStringWidthLoopOuter
  64. dbfStringWidth_Finish:
  65.     ex de,hl
  66.     bcall(_setxxxxop2)
  67.     bcall(_op2toop1)
  68.     ret
  69. ;================================
  70. dbfPxScan:
  71.     ld a,(var2)
  72.     ld e,a
  73.     ld a,(var1)
  74.     ld d,a
  75.     push de
  76.         call immGetPixel
  77.         pop de
  78.     ld c,a
  79.     ld a,(var3)
  80.     dec a
  81.     jr z,dbfPxScanUp
  82.     dec a
  83.     jr z,dbfPxScanDown
  84.     dec a
  85.     jr z,dbfPxScanLeft
  86. dbfPxScanRight:
  87.     ld a,96
  88.     sub d
  89.     ld b,a
  90.     ld a,(hl)
  91.     and c
  92.     ld d,a
  93. ;-------------------------------
  94. ; b: number of iterations
  95. ; d: pixel to xor with
  96. ; hl: address
  97. ; c: current mask
  98. dbfPxScanRightLoop:
  99.     ld a,b
  100.     or a
  101.     jr z,dbfPxScanRightEnd
  102.     dec b
  103.     rrc d
  104.     rrc c
  105.     jr nc,dbfPxScanRightNoInc
  106.     inc hl
  107. dbfPxScanRightNoInc:
  108.     ld a,(hl)
  109.     and c
  110.     xor d
  111.     jr z,dbfPxScanRightLoop
  112. dbfPxScanRightEnd:
  113.     ld a,96
  114.     sub b
  115. dbfPxScanRightEndSet:
  116.     bit 7,a
  117.     jr nz,dbfPxScanRightEndSetNeg
  118.     bcall(_SetXXOp1)
  119.     ret
  120. dbfPxScanRightEndSetNeg:
  121.     neg
  122.     bcall(_SetXXOp1)
  123.     bcall(_InvOp1S)
  124.     ret
  125. dbfPxScanLeft:
  126.     ld b,d
  127.     inc b
  128.     ld a,(hl)
  129.     and c
  130.     ld d,a
  131. ;-------------------------------
  132. ; b: number of iterations
  133. ; d: pixel to xor with
  134. ; hl: address
  135. ; c: current mask
  136. dbfPxScanLeftLoop:
  137.     ld a,b
  138.     or a
  139.     jr z,dbfPxScanLeftEnd
  140.     dec b
  141.     rlc d
  142.     rlc c
  143.     jr nc,dbfPxScanLeftNoInc
  144.     dec hl
  145. dbfPxScanLeftNoInc:
  146.     ld a,(hl)
  147.     and c
  148.     xor d
  149.     jr z,dbfPxScanLeftLoop
  150. dbfPxScanLeftEnd:
  151.     dec b
  152.     ld a,b
  153.     jr dbfPxScanRightEndSet
  154. dbfPxScanDown:
  155.     ld a,64
  156.     sub e
  157.     ld b,a
  158.     ld a,(hl)
  159.     and c
  160.     ld d,a
  161. ;-------------------------------
  162. ; b: number of iterations
  163. ; d: pixel to xor with
  164. ; hl: address
  165. ; c: current mask
  166. dbfPxScanDownLoop:
  167.     ld a,b
  168.     or a
  169.     jr z,dbfPxScanDownEnd
  170.     dec b
  171.     push de
  172.         ld de,12
  173.         add hl,de
  174.         pop de
  175.     ld a,(hl)
  176.     and c
  177.     xor d
  178.     jr z,dbfPxScanDownLoop
  179. dbfPxScanDownEnd:
  180.     ld a,64
  181.     sub b
  182.     jr dbfPxScanRightEndSet
  183. dbfPxScanUp:
  184.     ld b,e
  185.     inc b
  186.     ld a,(hl)
  187.     and c
  188.     ld d,a
  189. ;-------------------------------
  190. ; b: number of iterations
  191. ; d: pixel to xor with
  192. ; hl: address
  193. ; c: current mask
  194. dbfPxScanUpLoop:
  195.     ld a,b
  196.     or a
  197.     jr z,dbfPxScanUpEnd
  198.     dec b
  199.     push de
  200.         ld de,-12
  201.         add hl,de
  202.         pop de
  203.     ld a,(hl)
  204.     and c
  205.     xor d
  206.     jr z,dbfPxScanUpLoop
  207. dbfPxScanUpEnd:
  208.     dec b
  209.     ld a,b
  210.     jr dbfPxScanRightEndSet
  211.    
  212. ;================================
  213. dbfHometoGraph:
  214.     ld hl,textShadow
  215.     ld a,(iy+FontFlags)
  216.     push af
  217.         ld a,(iy+sGrFlags)
  218.         push af
  219.             set textWrite,(iy+sGrFlags)
  220.             set fracDrawLFont,(iy+fontFlags)
  221.             set fullScrnDraw,(iy+apiflg4)
  222.             set 4,(iy+24h)
  223.             ld b,8
  224.             xor a
  225.             bit grfSplit,(iy+SGrFlags)
  226.             jr z,dbfHometoGraphBegin
  227.             ld b,4
  228.             ld hl,textShadow+4*16
  229.             ld a,32
  230. dbfHometoGraphBegin:
  231.             ld (penrow),a
  232. dbfHometoGraphOuter:
  233.             xor a
  234.             ld (pencol),a
  235.             ld c,16
  236. dbfHometoGraphInner:
  237.             ld a,(hl)                   ;vputsmap destroys neither HL nor BC
  238.             bcall(_VPutMap)
  239.             inc hl
  240.             dec c
  241.             jr nz,dbfHometoGraphInner
  242.             push hl
  243.                 ld hl,penrow
  244.                 ld a,8
  245.                 add a,(hl)
  246.                 ld (hl),a
  247.                 pop hl
  248.             djnz dbfHometoGraphOuter
  249.             ld a,(var1)
  250.             or a
  251.             call nz,fastcopy
  252.             pop af
  253.         ld (iy+sGrFlags),a
  254.         pop af
  255.     ld (iy+FontFlags),a
  256.     jp xLIBEndNoOut
  257. ;================================
  258. dbfUsedPicList:
  259.     ld bc,0
  260.     ld de,-9
  261.     ld hl,SymTable
  262. dbfUsedPicList_Enumerate:
  263.     push de
  264.         ld de,(progptr)
  265.         bcall(_mos_cphlde)
  266.         pop de
  267.     jr z,dbfUsedPicList_Store
  268.     ld a,(hl)
  269.     and $1f
  270.     cp 7                                ;pic obj
  271.     jr nz,dbfUsedPicList_EnumNotPic
  272.     inc bc
  273. dbfUsedPicList_EnumNotPic:
  274.     add hl,de
  275.     jr dbfUsedPicList_Enumerate
  276. dbfUsedPicList_Store:
  277.     push bc
  278.         push bc
  279.             pop hl
  280.         ld a,h
  281.         or l
  282.         jr z,dbfUsedPicList_Empty
  283.         bcall(_CreateTRList)            ;create an hl-element list
  284.         inc de
  285.         inc de
  286.         pop bc
  287.     ld hl,SymTable
  288. dbfUsedPicList_StoreLoop:
  289.     ld a,b
  290.     or c
  291.     jr z,dbfUsedPicList_Finish
  292.     push de
  293.         ld de,(progptr)
  294.         bcall(_mos_cphlde)
  295.         pop de
  296.     jr z,dbfUsedPicList_Finish
  297.     ld a,(hl)
  298.     push de
  299.         ld de,-9
  300.         add hl,de
  301.         pop de
  302.     and $1f
  303.     cp 7                                ;pic obj
  304.     jr nz,dbfUsedPicList_StoreLoop
  305.     push hl
  306.         push bc
  307.             push de
  308.                 inc hl
  309.                 inc hl
  310.                 ld a,(hl)
  311.                 inc hl
  312.                 inc hl
  313.                 ld b,(hl)
  314.                 push bc
  315.                     inc a
  316.                     ld l,a
  317.                     ld h,0
  318.                     bcall(_SetXXXXOp2)
  319.                     pop af
  320.                 or a
  321.                 jr z,dbfUsedPicList_StoreLoopNoNegate
  322.                 bcall(_InvOP2S)
  323. dbfUsedPicList_StoreLoopNoNegate:
  324.                 ld hl,Op2
  325.                 pop de
  326.             ld bc,9
  327.             ldir
  328.             pop bc
  329.         pop hl
  330.     dec bc
  331.     jr dbfUsedPicList_StoreLoop
  332. dbfUsedPicList_Empty:
  333.         inc hl
  334.         bcall(_CreateTRList)            ;create an hl-element list
  335.         inc de
  336.         inc de
  337.         pop bc
  338.     push de
  339.         bcall(_Op1Set0)
  340.         ld hl,Op1
  341.         pop de
  342.     ld bc,9
  343.     ldir
  344. dbfUsedPicList_Finish:
  345.     bcall(_Op4ToOp1)
  346.     ret
  347. ;================================
  348. dbfArcUnarcPic:
  349.     ld hl,Op1
  350.     ld (hl),7                   ;tPictObj
  351.     inc hl
  352.     ld (hl),60h                 ;tVarPict
  353.     inc hl
  354.     ld a,(var1)
  355.     dec a
  356.     ld (hl),a
  357.     inc hl
  358.     ld (hl),0
  359.     bcall(_FindSym)
  360.     jr c,dbfArcUnarcPic_End
  361.     push bc
  362.         ld a,b
  363.         or a
  364.         jr z,dbfArcUnarcPicRAM
  365.         ld b,1
  366. dbfArcUnarcPicRAM
  367.         ld a,(var2)
  368.         cp b
  369.         pop bc
  370.     jr z,dbfArcUnarcPic_End
  371.     bcall(_Arc_Unarc)
  372. dbfArcUnarcPic_End:
  373.     jp xLIBEndNoOut
  374. ;================================
  375. dbfDCSLibVersion:
  376.     ld a,5
  377.     bcall(_setxxop1)
  378.     ret
  379. ;================================
  380. dbfMouseCoordSet:
  381.     ld a,(var1)             ;X
  382.     bit 7,a
  383.     jr z,dbfSimpleGUIMouse_Chk1
  384.     xor a
  385. dbfSimpleGUIMouse_Chk1:
  386.     cp 96
  387.     jr c,dbfSimpleGUIMouse_Chk2
  388.     ld a,95
  389. dbfSimpleGUIMouse_Chk2:
  390.     ld h,a
  391.     ld a,(var2)             ;Y
  392.     bit 7,a
  393.     jr z,dbfSimpleGUIMouse_Chk3
  394.     xor a
  395. dbfSimpleGUIMouse_Chk3:
  396.     cp 64
  397.     jr c,dbfSimpleGUIMouse_Chk4
  398.     ld a,63
  399. dbfSimpleGUIMouse_Chk4:
  400.     ld l,a
  401.     ld (MseY),hl
  402.     ret
  403. ;================================
  404. dbfSimpleGUIMouse:
  405.     call dbfMouseCoordSet
  406.     bcall(_OpenGUIStack)
  407.     push bc
  408.         ld hl,SimpleGUIMouseData
  409.         bcall(_PushGUIStacks)
  410.         ld hl,(stack)
  411.         push hl
  412.             ld hl,$0000
  413.             bcall(_GUIMouse)
  414. dbfSimpleGUIMouse_Process:
  415.             pop hl
  416.         ld (stack),hl
  417.         ld hl,3
  418.         bcall(_CreateTRList)
  419.         ex de,hl
  420.         inc hl
  421.         inc hl
  422.         ld a,(MseX)
  423.         call AtoRealAtHL
  424.         ld a,(MseY)
  425.         call AtoRealAtHL
  426.         ld a,(lastclick)
  427.         call AtoRealAtHL
  428.         ld b,2
  429.         bcall(_PopGUIStacks)
  430.         pop bc
  431.     ld a,c
  432.     or a
  433.     jr nz,dbfSimpleGUIMouse_Finish
  434.     bcall(_CloseGUIStack)
  435. dbfSimpleGUIMouse_Finish:
  436.     bcall(_Op4ToOp1)
  437.     ret
  438. ;================================
  439. dbfPushGUIStack:
  440.     ld hl,xLIBEndNoOut
  441.     push hl
  442.     ld a,(var1)                     ;get type int
  443.     cp 23d
  444.     ret z
  445.     cp 25d
  446.     ret nc                          ;24 is the highest allowed
  447.     ld h,0
  448.     ld l,a
  449.     add hl,hl
  450.     ld de,dbfPushGUIStack_EntryTable
  451.     add hl,de
  452.     push af                         ;save type
  453.         ld a,(hl)
  454.         inc hl
  455.         ld h,(hl)
  456.         ld l,a
  457.         pop af
  458.     jp (hl)
  459.  
  460. dbfPushGUIStack_EntryTable:
  461.     .dw dbfPGS_GUIRNull
  462.     .dw dbfPGS_GUIRLargeWin
  463.     .dw dbfPGS_GUIRSmallWin
  464.     .dw dbfPGS_GUIRFullScreenImg
  465.     .dw dbfPGS_GUIRText
  466.     .dw dbfPGS_GUIRWinButtons
  467.     .dw dbfPGS_GUIRWrappedText
  468.     .dw dbfPGS_GUIRButtonText
  469.     .dw dbfPGS_GUIRButtonImg
  470.     .dw dbfPGS_GUIRTextLineIn
  471.     .dw dbfPGS_GUIRRadio
  472.     .dw dbfPGS_GUIRCheckBox
  473.     .dw dbfPGS_GUIRByteInt
  474.     .dw dbfPGS_GUIRWordInt
  475.     .dw dbfPGS_GUIRHotspot
  476.     .dw dbfPGS_GUIRTextMultiline
  477.     .dw dbfPGS_GUIRSprite
  478.     .dw dbfPGS_GUIRLargeSprite
  479.     .dw dbfPGS_GUIRPassIn
  480.     .dw dbfPGS_GUIRScrollVert
  481.     .dw dbfPGS_GUIRScrollHoriz
  482.     .dw dbfPGS_GUIRBorder
  483.     .dw dbfPGS_GUIRRect
  484.     .dw 0000
  485.     .dw dbfPGS_GUIRMouseCursor
  486. ;================================
  487. dbfPGS_GUIRNull:
  488.     ld de,1
  489.     bcall(_PushGUIStack)                ;a is set up, hl doesn't matter
  490.     ld a,(var2)
  491.     ld (hl),a
  492.     ret
  493. dbfPGS_GUIRLargeWin:
  494.     ld hl,sc2
  495.     ld de,5+1                           ;one of these is the zero term
  496.     call dbfPGS_GetStrlenToDE_SaveA
  497. dbfPGS_GUIRWinFinish:
  498.     push hl
  499.         ld hl,sc1
  500.         call getsourcestring
  501.         pop de
  502.     ex de,hl
  503.     ld bc,5
  504.     push hl
  505.         push bc
  506.             call HexStringToBin
  507.             pop bc
  508.         pop hl
  509.     add hl,bc                   ;bc=5 is already set up here
  510.     ld de,sc2
  511.     jp copysourcestring_plain_zt
  512.  
  513. dbfPGS_GUIRSmallWin:
  514.     ld hl,sc2
  515.     ld de,5+1+1+1               ;one of these is the zero term
  516.     call dbfPGS_GetStrlenToDE_SaveA
  517.     ld b,2
  518.     call dbfPGS_LoadVarsToHL
  519.     jr dbfPGS_GUIRWinFinish
  520. dbfPGS_GUIRFullScreenImg:
  521.     ld hl,var2
  522.     dec (hl)                            ;Pic1 = 0, Pic9=8, Pic0=9, etc
  523.     ld a,(hl)
  524.     call SearchForPic
  525.     ret c
  526.     ld a,b
  527.     or a
  528.     ret nz
  529.     ld a,03
  530.     ld de,768
  531.     bcall(_PushGUIStack)
  532.     ld a,(var2)
  533.     push hl
  534.         call SearchForPic
  535.         pop hl
  536.     inc de
  537.     inc de
  538.     ex de,hl
  539.     ld bc,768-12
  540.     ldir
  541.     push de
  542.         pop hl
  543.     ld (hl),0
  544.     inc de
  545.     ld bc,11
  546.     ldir
  547.     ret
  548.    
  549. dbfPGS_GUIRText:
  550.     ld hl,sc1
  551.     ld de,1+1+1+1                           ;one of these is the zero term
  552.     call dbfPGS_GetStrlenToDE_SaveA
  553.     ld b,3
  554.     call dbfPGS_LoadVarsToHL
  555.     ld de,sc1
  556.     jp copysourcestring_plain_zt
  557.  
  558. dbfPGS_GUIRWinButtons:
  559.     ld de,7
  560.     ld hl,dbfPGS_Template_GUIRWinButtons
  561.     bcall(_PushGUIStack)
  562.     ld a,(var2)
  563.     ld (hl),a
  564.     inc hl
  565.     ld b,3
  566. dbfPGS_GUIRWinButtons_ClearLoop:
  567.     push af
  568.         and %10000000
  569.         jr nz,dbfPGS_GUIRWinButtons_ClearLoopEnd
  570.         ;a is already zero!
  571.         ld (hl),a
  572.         inc hl
  573.         ld (hl),a
  574.         dec hl
  575. dbfPGS_GUIRWinButtons_ClearLoopEnd:
  576.         inc hl
  577.         inc hl
  578.         pop af
  579.     sla a
  580.     djnz dbfPGS_GUIRWinButtons_ClearLoop
  581.     ret
  582.  
  583. dbfPGS_GUIRWrappedText:
  584.     ld hl,sc1
  585.     ld de,4+1                           ;one of these is the zero term
  586.     call dbfPGS_GetStrlenToDE_SaveA
  587.     ld b,4
  588.     call dbfPGS_LoadVarsToHL
  589.     ld de,sc1
  590.     jp copysourcestring_plain_zt
  591.  
  592. dbfPGS_GUIRButtonText:
  593.     ld hl,sc1
  594.     ld de,4+1                           ;one of these is the zero term
  595.     call dbfPGS_GetStrlenToDE_SaveA
  596.     ld b,2
  597.     call dbfPGS_LoadVarsToHL
  598.     call dbfPGS_InsGMRPtr
  599.     ld de,sc1
  600.     jp copysourcestring_plain_zt
  601.  
  602. dbfPGS_GUIRButtonImg:
  603.     ld a,(var4)
  604.     push af
  605.         add a,a
  606.         add a,a
  607.         pop bc
  608.     add a,b
  609.     ld l,a
  610.     ld h,0
  611.     push hl
  612.         ld de,6
  613.         add hl,de
  614.         ld a,8
  615.         ex de,hl
  616.         bcall(_PushGUIStack)
  617.         ld b,2
  618.         call dbfPGS_LoadVarsToHL
  619.         call dbfPGS_InsGMRPtr
  620.         ld a,(var4)
  621.         ld (hl),a
  622.         inc hl
  623.         ld a,(var5)
  624.         ld (hl),a
  625.         inc hl
  626.         push hl
  627.             ld hl,sc1
  628.             call getsourcestring
  629.             pop de
  630.         ex de,hl
  631.         pop bc
  632.     jp HexStringToBin           ;de->hl for bc target bytes
  633.  
  634. dbfPGS_GUIRTextLineIn:
  635.     ld hl,sc1
  636.     ld de,7+1                           ;one of these is the zero term
  637.     call dbfPGS_GetStrlenToDE_SaveA
  638.     ld b,3
  639.     call dbfPGS_LoadVarsToHL
  640.     ld de,(var5)
  641.     ld (hl),e
  642.     inc hl
  643.     ld (hl),d
  644.     xor a
  645.     inc hl
  646.     ld (hl),a
  647.     inc hl
  648.     ld (hl),a
  649.     inc hl
  650.     ld de,sc1
  651.     jp copysourcestring_plain_zt
  652.  
  653. dbfPGS_GUIRRadio:
  654. dbfPGS_GUIRCheckBox:
  655.     ld hl,sc1
  656.     ld de,7+1                           ;one of these is the zero term
  657.     call dbfPGS_GetStrlenToDE_SaveA
  658.     ld b,4
  659.     call dbfPGS_LoadVarsToHL
  660.     ld de,sc1
  661.     jp copysourcestring_plain_zt
  662.  
  663. dbfPGS_GUIRByteInt:
  664.     ld de,5
  665.     bcall(_PushGUIStack)
  666.     ld b,5
  667.     jp dbfPGS_LoadVarsToHL
  668.  
  669. dbfPGS_GUIRWordInt:
  670.     ld de,10
  671.     bcall(_PushGUIStack)
  672.     ld b,2
  673.     call dbfPGS_LoadVarsToHL
  674.     ld de,var4
  675.     ld bc,3*2
  676.     ex de,hl
  677.     ldir
  678.     ret
  679.  
  680. dbfPGS_GUIRHotspot:
  681.     ld de,6
  682.     bcall(_PushGUIStack)
  683.     ld b,4
  684.     call dbfPGS_LoadVarsToHL
  685.     jp dbfPGS_InsGMRPtr
  686.  
  687. dbfPGS_GUIRTextMultiline:
  688.     ld hl,sc1
  689.     ld de,6+1                           ;one of these is the zero term
  690.     call dbfPGS_GetStrlenToDE_SaveA
  691.     ld b,4
  692.     call dbfPGS_LoadVarsToHL
  693.     xor a
  694.     ld (hl),a
  695.     inc hl
  696.     ld (hl),a
  697.     inc hl
  698.     ld de,sc1
  699.     jp copysourcestring_plain_zt
  700.  
  701. dbfPGS_GUIRSprite:
  702.     push af
  703.         ld a,(var4)
  704.         ld e,a
  705.         ld d,0
  706.         ld hl,3
  707.         add hl,de
  708.         pop af
  709.     ex de,hl
  710.     bcall(_PushGUIStack)
  711.     ld b,3
  712.     call dbfPGS_LoadVarsToHL
  713.     push hl
  714.         ld hl,sc1
  715.         call getsourcestring
  716.         pop de
  717.     ex de,hl
  718.     ld a,(var4)
  719.     ld c,a
  720.     ld b,0
  721.     jp HexStringToBin           ;de->hl for bc target bytes
  722.    
  723. dbfPGS_GUIRLargeSprite:
  724.     push af
  725.         ld a,(var4)
  726.         ld e,a
  727.         ld d,0
  728.         ld a,(var5)
  729.         bcall(_MultADE)
  730.         pop af
  731.     push hl
  732.         ld de,4
  733.         add hl,de
  734.         ex de,hl
  735.         bcall(_PushGUIStack)
  736.         ld b,4
  737.         call dbfPGS_LoadVarsToHL
  738.         push hl
  739.             ld hl,sc1
  740.             call getsourcestring
  741.             pop de
  742.         ex de,hl
  743.         pop bc
  744.     jp HexStringToBin           ;de->hl for bc target bytes
  745.  
  746. dbfPGS_GUIRPassIn:
  747.     ld hl,sc1
  748.     ld de,7+1                           ;one of these is the zero term
  749.     call dbfPGS_GetStrlenToDE_SaveA
  750.     ld b,3
  751.     call dbfPGS_LoadVarsToHL
  752.     ld de,(var5)
  753.     ld (hl),e
  754.     inc hl
  755.     ld (hl),d
  756.     inc hl
  757.     xor a
  758.     ld (hl),a
  759.     inc hl
  760.     ld (hl),a
  761.     inc hl
  762.     ld de,sc1
  763.     jp copysourcestring_plain_zt
  764.  
  765. dbfPGS_GUIRScrollVert:
  766. dbfPGS_GUIRScrollHoriz:
  767.     ld de,16
  768.     bcall(_PushGUIStack)
  769.     ld b,4
  770.     call dbfPGS_LoadVarsToHL
  771.     ld de,var6
  772.     ld bc,8
  773.     ex de,hl
  774.     ldir
  775.     ex de,hl
  776.     call dbfPGS_InsGMRPtr
  777.     jp dbfPGS_InsGMRPtr
  778.    
  779. dbfPGS_GUIRBorder:
  780. dbfPGS_GUIRRect:
  781.     ld de,5
  782.     bcall(_PushGUIStack)
  783.     ld b,5
  784.     jp dbfPGS_LoadVarsToHL
  785.  
  786. dbfPGS_GUIRMouseCursor:
  787.     ld de,2+2+8+8
  788.     bcall(_PushGUIStack)
  789.     ld de,var2
  790.     ld bc,4
  791.     ex de,hl
  792.     ldir
  793.     push de
  794.         ld hl,sc1
  795.         call getsourcestring
  796.         pop de
  797.     ex de,hl
  798.     ld bc,8
  799.     push bc
  800.         call HexStringToBin         ;de->hl for bc target bytes
  801.         push hl
  802.             ld hl,sc2
  803.             call getsourcestring
  804.             pop de
  805.         ex de,hl
  806.         pop bc
  807.     jp HexStringToBin           ;de->hl for bc target bytes
  808.  
  809. ;================================
  810.  
  811. dbfPGS_LoadVarsToHL:        ;13-byte routine
  812.     push de
  813.         ld de,var2
  814. dbfPGS_LoadVarsLoop:
  815.         ld a,(de)
  816.         ld (hl),a
  817.         inc de \ inc de
  818.         inc hl
  819.         djnz dbfPGS_LoadVarsLoop
  820.         pop de
  821.     ret
  822. dbfPGS_InsGMRPtr:
  823.     ld de,dbfGUIMouse_Return
  824.     ld (hl),e
  825.     inc hl
  826.     ld (hl),d
  827.     inc hl
  828.     ret
  829. dbfPGS_GetStrlenToDE_SaveA:
  830.     push de
  831.         push af
  832.             call getsourcestring_plain
  833. ;           ld a,d
  834. ;           or e
  835.             pop bc
  836.         pop hl
  837. ;   jr z,dbfPGS_GetStrlenToDE_SaveA_Ret
  838.     ld a,b
  839.     add hl,de
  840.     ex de,hl
  841.     bcall(_PushGUIStack)
  842.     ret
  843. ;dbfPGS_GetStrlenToDE_SaveA_Ret:
  844. ;   pop hl              ;the call from the function
  845. ;   ret
  846.  
  847. ;================================
  848. dbfPopGUIStack:
  849.     ld a,(var1)
  850.     or a
  851.     jr z,dbfPopGUIStackFinish
  852.     ld b,a
  853.     bcall(_PopGUIStacks)
  854. dbfPopGUIStackFinish:
  855.     jp xLIBEndNoOut
  856. ;================================
  857. dbfOpenGUIStack:
  858.     bcall(_OpenGUIStack)
  859.     jp xLIBEndNoOut
  860. ;================================
  861. dbfCloseGUIStack:
  862.     bcall(_CloseGUIStack)
  863.     jp xLIBEndNoOut
  864. ;================================
  865. dbfRenderGUIStack:
  866.     ld a,(nargs)
  867.     sub 2
  868.     ld b,a
  869.     ld a,(var1)
  870.     or b
  871.     push af
  872.         bcall(_RenderGUISub)
  873.         pop af
  874.     call nz,immFastCopy
  875.     jp xLIBEndNoOut
  876. ;================================
  877. dbfGUIMouse:
  878.     call dbfMouseCoordSet
  879.     ld hl,(stack)
  880.     push hl
  881.         ld hl,(var3)
  882.         push hl
  883.             ld hl,sum12MouseHookHotspot
  884.             ld de,6
  885.             ld a,$0E
  886.             bcall(_PushGUIStack)
  887.             ld hl,sum12MouseHook
  888.             bcall(_GUIMouse)
  889.  
  890. dbfGUIMouse_ReturnP2:
  891.             bcall(_PopGUIStack)
  892.             pop hl
  893.         ld (var3),hl
  894.         pop hl
  895.     ld (stack),hl
  896.     xor a
  897.     ld (ScratchVar),a
  898.     push ix                             ;save trigger item for the end of this routine
  899.    
  900.     ;create output string for data
  901.     ;first pass: size
  902.     bcall(_GUIFindFirst)
  903.     ld bc,0
  904. dbfGUIMouse_StringSizeLoop:
  905.     bcall(_mos_cphlde)
  906.     jp z,dbfGUIMouse_StringSave
  907.     push hl
  908.         push hl
  909.             pop ix
  910.         push de
  911.             push bc
  912.                 inc hl
  913.                 inc hl
  914.                 ld a,(hl)
  915.                 sub 9
  916.                 jr c,dbfGUIMouse_StringSizeContinue
  917.                 cp 18+1-9
  918.                 jr nc,dbfGUIMouse_StringSizeContinue
  919.                 ld l,a
  920.                 ld h,0
  921.                 add hl,hl
  922.                 ld de,dbfGUIMouseRet_StringDataVecT
  923.                 add hl,de
  924.                 ld a,(hl)
  925.                 inc hl
  926.                 ld h,(hl)
  927.                 ld l,a
  928.                 or h
  929.                 jr z,dbfGUIMouse_StringSizeContinue
  930.                 ld a,(ScratchVar)
  931.                 or a
  932.                 jr z,dbfGUIMouse_StringSize_NoDelimitYet
  933.                 pop bc
  934.             ld a,$80            ;tCrossIcon
  935.             ld (bc),a
  936.             inc bc
  937.             push bc
  938. dbfGUIMouse_StringSize_NoDelimitYet:
  939.                 ld de,dbfGUIMouse_StringReturn
  940.                 push de
  941.                     jp (hl)
  942. dbfGUIMouse_StringReturn:           ;hl = data loc, de=data size
  943.                 ld a,(ScratchVar)
  944.                 or a
  945.                 jr z,dbfGUIMouse_StringReturn_Count
  946.                 ld a,e
  947.                 or d
  948.                 jr z,dbfGUIMouse_StringSizeContinue
  949.                 ex de,hl
  950.                 push hl
  951.                     pop bc          ;size in bc, location in de
  952.                 pop hl              ;destination location in hl
  953.             ex de,hl            ;size in bc, source in hl, destination in de
  954. dbfGUIMouse_StringReturnStoreLoop:
  955.             ld a,(hl)
  956.             cp $D6
  957.             jr nz,dbfGUIMouse_StringReturnStoreLoop1
  958.             inc hl                      ;the extra byte after the CRLF byte
  959.             dec bc
  960. dbfGUIMouse_StringReturnStoreLoop1:
  961.             push hl
  962.                                         ;the following routine needs to preserve de, bc
  963.                 call Get_Strng_Tok      ;token in h,l; z set if one-byte tok (in l only)
  964.                 ex de,hl
  965.                 jr z,dbfGUIMouse_StringReturnStoreLoop_Single
  966.                 ld (hl),d
  967.                 inc hl
  968. dbfGUIMouse_StringReturnStoreLoop_Single:
  969.                 ld (hl),e
  970.                 ex de,hl
  971.                 inc de
  972.                 pop hl
  973.             inc hl
  974.             dec bc
  975.             ld a,b
  976.             or c
  977.             jr nz,dbfGUIMouse_StringReturnStoreLoop
  978.             push de
  979.                 jr dbfGUIMouse_StringSizeContinue
  980. dbfGUIMouse_StringReturn_Count:
  981.                 ld a,e
  982.                 or d
  983.                 jr z,dbfGUIMouse_StringSizeContinueIncBC
  984.                 ld bc,0
  985. dbfGUIMouse_StringReturnLenLoop:
  986.                 ld a,(hl)
  987.                 cp $D6
  988.                 jr nz,dbfGUIMouse_StringReturnLenLoop1
  989.                 inc hl                      ;the extra byte after the CRLF byte
  990.                 dec de
  991. dbfGUIMouse_StringReturnLenLoop1:
  992.                 push hl
  993.                     inc bc                  ;the following routine needs to preserve de, bc
  994.                     call Get_Strng_Tok      ;token in h,l; z set if one-byte tok (in l only)
  995.                     jr z,dbfGUIMouse_StringReturnLenLoop_Single
  996.                     inc bc
  997. dbfGUIMouse_StringReturnLenLoop_Single:
  998.                     pop hl
  999.                 inc hl
  1000.                 dec de
  1001.                 ld a,d
  1002.                 or e
  1003.                 jr nz,dbfGUIMouse_StringReturnLenLoop
  1004.                 ;inc bc                     ;for ┼ (128d = 0x80 token)
  1005.                 pop hl          ;recall old size
  1006.             add hl,bc
  1007.             push hl
  1008. dbfGUIMouse_StringSizeContinueIncBC:
  1009.                 pop bc
  1010.             inc bc
  1011.             push bc
  1012. dbfGUIMouse_StringSizeContinue:
  1013.                 pop bc
  1014.             pop de
  1015.         pop hl
  1016.     push bc
  1017.         bcall(_GUIFindNext)
  1018.         pop bc
  1019.     jp dbfGUIMouse_StringSizeLoop
  1020.  
  1021.     ;second pass: contents
  1022. dbfGUIMouse_StringSave:
  1023.     ld a,(ScratchVar)
  1024.     inc a
  1025.     ld (ScratchVar),a
  1026.     dec a
  1027.     jr nz,dbfGUIMouse_ListOutput
  1028.     ;size is in bc, string number is in var3
  1029.     ld a,(var3)
  1030.     or a
  1031.     jr nz,dbfGUIMouse_StringSave_Not0
  1032.     ld a,10
  1033. dbfGUIMouse_StringSave_Not0:
  1034.     push bc
  1035.         dec a
  1036.         ld hl,Op1
  1037.         ld (hl),4
  1038.         inc hl
  1039.         ld (hl),$AA
  1040.         inc hl
  1041.         ld (hl),a
  1042.         inc hl
  1043.         ld (hl),0
  1044.         rst 10h                 ;findsym
  1045.         bcallnc(_DelVarArc)
  1046.         pop hl
  1047.     bcall(_EnoughMem)
  1048.     jr c,dbfGUIMouse_ListOutput         ;Insufficient memory
  1049.     ex de,hl
  1050.     bcall(_CreateStrng)
  1051.     inc de
  1052.     inc de
  1053.     push de
  1054.         bcall(_GUIFindFirst)
  1055.         pop bc                          ;variable storage in bc
  1056.     jp dbfGUIMouse_StringSizeLoop
  1057.    
  1058. dbfGUIMouse_ListOutput:
  1059.     ;save common info in list
  1060.         ld hl,4
  1061.         bcall(_CreateTRList)
  1062.         ex de,hl
  1063.         inc hl
  1064.         inc hl
  1065.         ld a,(MseX)
  1066.         call AtoRealAtHL
  1067.         ld a,(MseY)
  1068.         call AtoRealAtHL
  1069.         ld a,(lastclick)
  1070.         call AtoRealAtHL
  1071.         pop bc
  1072.     ld a,c
  1073.     call AtoRealAtHL
  1074.    
  1075.     bcall(_Op4ToOp1)
  1076.     ret
  1077.  
  1078. dbfGUIMouseRet_StringDataVecT:
  1079. ;NOTE**: STARTS AT ITEM 9, NOT ZERO
  1080. ;NOTE**: Each of these takes the pointer to the current item @ ix
  1081. ;NOTE**: Each of these should return data @ hl, length in de
  1082.     .dw dbfGUIMouseRet_Sum9
  1083.     .dw dbfGUIMouseRet_Sum10
  1084.     .dw dbfGUIMouseRet_Sum11
  1085.     .dw dbfGUIMouseRet_Sum12
  1086.     .dw dbfGUIMouseRet_Sum13
  1087.     .dw 0
  1088.     .dw dbfGUIMouseRet_Sum15
  1089.     .dw 0
  1090.     .dw 0
  1091.     .dw dbfGUIMouseRet_Sum18
  1092. ;NOTE**: ENDS AT ITEM 18, NOT 24
  1093. ;================================
  1094. dbfGUIMouseRet_Sum9:
  1095. dbfGUIMouseRet_Sum18:
  1096.     push ix
  1097.         pop hl
  1098.     ld e,(hl)
  1099.     inc hl
  1100.     ld d,(hl)
  1101.     ld bc,9
  1102.     add hl,bc
  1103.     push hl
  1104.         ld hl,-10-1         ;NO ZERO TERM!
  1105.         add hl,de
  1106.         pop de
  1107.     ex de,hl                ;size in de, location in hl
  1108.     ret
  1109. dbfGUIMouseRet_Sum10:
  1110. dbfGUIMouseRet_Sum11:
  1111.     ld a,(ix+6)
  1112.     add a,'0'
  1113.     ld hl,Op1
  1114.     ld (hl),a
  1115.     ld de,1
  1116.     ret
  1117. dbfGUIMouseRet_Sum12:
  1118.     ld h,0
  1119.     jr dbfGUIMouseRet_Sum13_Finish
  1120. dbfGUIMouseRet_Sum13:
  1121.     ld h,(ix+6)
  1122. dbfGUIMouseRet_Sum13_Finish:
  1123.     ld l,(ix+5)
  1124.     xor a
  1125.     ld (Op1+5),a
  1126.     ld de,Op1
  1127.     push de
  1128.         call convHLtoDec
  1129.         pop hl
  1130.     ld de,5         ;NO ZERO TERM!
  1131.     ret
  1132. dbfGUIMouseRet_Sum15:
  1133.     push ix
  1134.         pop hl
  1135.     ld e,(hl)
  1136.     inc hl
  1137.     ld d,(hl)
  1138.     ld bc,8
  1139.     add hl,bc
  1140.     push hl
  1141.         ld hl,-9-1          ;NO ZERO TERM!
  1142.         add hl,de
  1143.         pop de
  1144.     ex de,hl                ;size in de, location in hl
  1145.     ret
  1146. ;================================
  1147. temp1b      .equ    temp1
  1148. temp2b      .equ    temp1+1
  1149. temp3b      .equ    temp2
  1150. temp4b      .equ    temp2+1             ;at +4, IconSpace8b (scroll data saferam) begins
  1151.  
  1152. dbfMenu:
  1153.     ld a,(sargs)
  1154.     push af
  1155.         bcall(_APGui_gui7ToTop)
  1156.         bcall(_OpenGUIStack)
  1157.         push bc                             ;save whether the GUI was open previously
  1158.             ;add initial items onto GUI stack
  1159.             ld hl,sc1
  1160.             call getsourcestring            ;returns string size in chars in bc
  1161.             ld hl,1+1+5+1
  1162.             add hl,bc                       ;string size + 0 term + 5-byte icon + coord-x + coord-y
  1163.             ld de,dbfMenuTemp_SMW
  1164.             ex de,hl
  1165.             ld a,2                          ;GUIRSmallWin
  1166.             bcall(_PushGUIStack)            ;returns coordinate in HL
  1167.             ld b,2
  1168.             ld de,var1
  1169. dbfMenu_LoadCoordsLoop:
  1170.             ld a,(de)
  1171.             ld (hl),a
  1172.             inc de \ inc de
  1173.             inc hl
  1174.             djnz dbfMenu_LoadCoordsLoop
  1175.             push hl
  1176.                 ld hl,sc2
  1177.                 call getsourcestring
  1178.                 pop de
  1179.             ex de,hl
  1180.             ld bc,5
  1181.             call HexStringToBin         ;de->hl for bc target bytes, returns final HL
  1182.             ld de,sc1
  1183.             call copysourcestring_plain_zt
  1184.             ;completed constructing the GUIRSmallWin now
  1185.             ld hl,dbfMenuTemp_Scroll
  1186.             ld de,dbfMenuTemp_ScrollEnd-dbfMenuTemp_Scroll
  1187.             ld a,$13
  1188.             bcall(_PushGUIStack)
  1189.             ld de,4
  1190.             add hl,de                   ;at the "max" value
  1191.             push hl
  1192.                 ld hl,sc3               ;time to find the length
  1193.                 call getsourcestring
  1194.                 ld d,0
  1195. dbfMenu_ItemCountLoop:
  1196.                 ld a,b
  1197.                 or c
  1198.                 jr z,dbfMenu_ItemCountFinish
  1199.                 ld a,(hl)
  1200.                 cp $80                  ;tCrossIcon
  1201.                 jr nz,$+5
  1202.                 ld (hl),0               ;divide them with zero terms for simplicity
  1203.                 inc d
  1204.                 inc hl
  1205.                 dec bc
  1206.                 bcall(_IsA2ByteTok)
  1207.                 jr nz,dbfMenu_ItemCountLoop
  1208.                 inc hl
  1209.                 dec bc
  1210.                 jr dbfMenu_ItemCountLoop
  1211. dbfMenu_ItemCountFinish:
  1212.                 ld a,d
  1213.                 pop hl                  ;item count returned in a
  1214.             ld (temp1b),a               ;temp1 is the total item count
  1215.             push af
  1216.                 cp 6
  1217.                 jr c,$+4
  1218.                 ld a,6
  1219.                 ld (hl),a
  1220.                 inc hl
  1221.                 ld (hl),0
  1222.                 pop af
  1223.             inc hl
  1224.             inc hl
  1225.             inc hl
  1226.             ld (hl),a
  1227.             inc hl
  1228.             ld (hl),0                   ;two-byte word value
  1229.             ld hl,dbfMenuTemp_WinB
  1230.             ld de,7
  1231.             ld a,5
  1232.             bcall(_PushGUIStack)
  1233.             xor a
  1234.             ld (temp2b),a               ;current scroll value
  1235.             ld (temp4b),a               ;current item (0-5)
  1236. dbfMenu_MainOuter:
  1237.             bcall(_GUIFindFirst)
  1238.             ld de,10+3
  1239.             add hl,de
  1240.             ld a,(temp2b)
  1241.             ld (hl),a
  1242.             ld a,1
  1243.             ld (temp3b),a               ;y-coord of current item
  1244.             ld hl,sc3
  1245.             call getsourcestring
  1246.             ld a,(temp2b)
  1247. dbfMenu_MainFindFirst:
  1248.             or a
  1249.             jr z,dbfMenu_MainDisp
  1250.             push af
  1251.                 call dbfMenu_GetNextItem    ;moves hl from start of this item to start of next
  1252.                 pop af
  1253.             dec a
  1254.             jr dbfMenu_MainFindFirst
  1255. dbfMenu_MainDisp:
  1256.             ld a,(temp2b)
  1257.             ld b,a
  1258. dbfMenu_MainDispLoop:
  1259.             ld a,(temp1b)
  1260.             cp b
  1261.             jr z,dbfMenu_KeyStart
  1262.             ld a,(temp2b)
  1263.             add a,6
  1264.             cp b
  1265.             jr z,dbfMenu_KeyStart
  1266.             push bc
  1267.                 ld (RelocatablePtr2),hl
  1268.                     push hl
  1269.                         call dbfMenu_GetNextItem
  1270.                         pop hl
  1271.                     push hl
  1272.                         pop ix
  1273.                     dec de                  ;zero term
  1274.                     push de
  1275.                         push de
  1276.                             pop bc
  1277.                         ld de,0
  1278.                         call getsourcestring_loop
  1279.                         inc de              ;for the zterm
  1280.                         ld hl,3
  1281.                         add hl,de
  1282.                         ex de,hl
  1283.                         ld a,4
  1284.                         bcall(_PushGUIStack)
  1285.                         ld (hl),1
  1286.                         inc hl
  1287.                         ld a,(temp3b)
  1288.                         ld (hl),a
  1289.                         add a,6
  1290.                         ld (temp3b),a
  1291.                         inc hl
  1292.                         ld (hl),0
  1293.                         inc hl
  1294.                         pop bc                          ;size to copy
  1295.                     ld de,(RelocatablePtr2)
  1296.                 push de
  1297.                     ex de,hl                            ;de is where to put it, hl is source
  1298.                     call copysourcestring_plain_zt_raw
  1299.                     pop hl
  1300.                 call dbfMenu_GetNextItem
  1301.                 pop bc
  1302.             inc b
  1303.             jr dbfMenu_MainDispLoop
  1304. dbfMenu_KeyStart:
  1305.             bcall(_RenderGUI)
  1306.             ld b,6
  1307.             ld a,(temp1b)
  1308.             cp b
  1309.             jr nc,dbfMenu_KeyStart_Pops
  1310.             ld b,a
  1311. dbfMenu_KeyStart_Pops:
  1312.             bcall(_PopGUIStacks)
  1313. dbfMenu_KeyRectDraw:
  1314.             call dbfMenu_DrawEraseRect
  1315.             call fastcopy
  1316. dbfMenu_KeyLoop:
  1317.             bcall(_Cn2GetK)             ;a is key, e is group
  1318.             or a
  1319.             jr z,dbfMenu_KeyLoop
  1320.             dec a
  1321.             jp z,dbfMenu_KeyDown
  1322.             cp 4-1
  1323.             jp z,dbfMenu_KeyUp
  1324.             cp 9h-1
  1325.             jr z,dbfMenu_KeyGo
  1326.             cp 36h-1
  1327.             jr nz,dbfMenu_KeyLoop
  1328. dbfMenu_KeyGo:     
  1329.             pop bc
  1330.         ld a,c
  1331.         or a
  1332.         jr nz,dbfMenu_DonePops              ;if jump, it was already open
  1333.         bcall(_CloseGUIStack)
  1334.         jr dbfMenuGoto
  1335. dbfMenu_DonePops:
  1336.         ld b,3
  1337.         bcall(_PopGUIStacks)
  1338. dbfMenuGoto:
  1339.         pop af
  1340.     cp 4
  1341.     jr nz,dbfMenuGoto_RetAns
  1342.     ld hl,sc4
  1343.     call getsourcestring
  1344.     jr z,dbfMenuGoto_RetAns                 ;trigger a lbl error
  1345.     ld a,(temp2b)
  1346.     ld e,a
  1347.     ld a,(temp4b)
  1348.     add a,e
  1349.     ld e,a
  1350.     ld d,0
  1351.     add hl,de
  1352.     add hl,de                           ;hl is now first of two chars
  1353.     ld de,(basic_start)
  1354.     ex de,hl
  1355. dbfMenuGotoLoop:
  1356.     push de
  1357.         ld de,(basic_end)
  1358.         bcall(_mos_cphlde)
  1359.         pop de
  1360.     jr z,dbfMenuGotoErr
  1361.     ld a,(hl)
  1362.     cp $D6                              ;tLbl
  1363.     jr nz,dbfMenuGotoContinue
  1364.     inc hl
  1365.     ld a,(de)
  1366.     cp $29                              ;space ' '
  1367.     jr z,dbfMenuGotoCheckOneChar
  1368.     cp (hl)
  1369.     jr nz,dbfMenuGotoContinue
  1370.     inc hl
  1371.     inc de
  1372.     ld a,(de)
  1373.     cp (hl)
  1374.     jr z,dbfMenuGotoFound
  1375.     dec hl
  1376.     dec de
  1377.     jr dbfMenuGotoContinue
  1378. dbfMenuGotoCheckOneChar:
  1379.     inc de
  1380.     ld a,(de)
  1381.     dec de
  1382.     cp (hl)
  1383.     jr nz,dbfMenuGotoContinue
  1384.     inc hl
  1385.     ld a,(hl)
  1386.     dec hl
  1387.     cp $3E
  1388.     jr z,dbfMenuGotoFound
  1389.     cp $3F
  1390.     jr z,dbfMenuGotoFound
  1391. dbfMenuGotoContinue:
  1392.     ld a,(hl)
  1393.     inc hl
  1394.     bcall(_IsA2ByteTok)
  1395.     jr nz,dbfMenuGotoLoop
  1396.     inc hl
  1397.     jr dbfMenuGotoLoop
  1398.     ;LOOP TO FIND Lbl
  1399.     ;CHECK THE Lbl tag
  1400.     ;JUMP OUT OR CONTINUE
  1401.     ;IF REACH THE END, TRIGGER ERROR
  1402.     ;NEED TO CHANGE BASIC_PC HERE!!!
  1403. dbfMenuGoto_RetAns:
  1404.     ld a,(temp2b)
  1405.     ld e,a
  1406.     ld a,(temp4b)
  1407.     add a,e
  1408.     bcall(_SetXXOp1)
  1409.     ret
  1410. dbfMenuGotoFound:
  1411.     inc hl
  1412.     ld (basic_pc),hl
  1413.     jp xLIBEndNoOut
  1414. dbfMenuGotoErr:
  1415.     ld a,20+$80
  1416.     b_jump(_JError)
  1417.  
  1418. dbfMenu_KeyUp:
  1419.     call dbfMenu_DrawEraseRect
  1420.     ld a,(temp4b)
  1421.     or a
  1422.     jr nz,dbfMenu_KeyUpSimple
  1423.     ld a,(temp2b)
  1424.     or a
  1425.     jr z,dbfMenu_KeyRectDrawGo
  1426.     dec a
  1427.     ld (temp2b),a
  1428.     jp dbfMenu_MainOuter
  1429. dbfMenu_KeyUpSimple:
  1430.     dec a
  1431.     ld (temp4b),a
  1432.     jr dbfMenu_KeyRectDrawGo
  1433. dbfMenu_KeyDown:
  1434.     call dbfMenu_DrawEraseRect
  1435.     ld a,(temp1b)
  1436.     ld b,a
  1437.     ld a,(temp4b)
  1438.     cp 5
  1439.     jr z,dbfMenu_KeyDownPage
  1440.     dec b
  1441.     cp b
  1442.     jr z,dbfMenu_KeyRectDrawGo
  1443.     inc a
  1444.     ld (temp4b),a
  1445. dbfMenu_KeyRectDrawGo:
  1446.     jp dbfMenu_KeyRectDraw
  1447. dbfMenu_KeyDownPage:
  1448.     ld a,(temp2b)
  1449.     add a,6
  1450.     cp b
  1451.     jp z,dbfMenu_KeyRectDrawGo
  1452.     sub 5               ;sub 6 \ inc a
  1453.     ld (temp2b),a
  1454.     jp dbfMenu_MainOuter
  1455. dbfMenu_DrawEraseRect:
  1456.     ld a,(temp4b)
  1457.     add a,a
  1458.     ld b,a
  1459.     add a,a
  1460.     add a,b                 ;a=a*6
  1461.     inc a                   ;a=1+a*6
  1462.     ld e,a
  1463.     ld d,0
  1464.     push de
  1465.         bcall(_RenderGUIGetWinX)
  1466.         pop de
  1467.     ld a,(hl)
  1468.     inc hl
  1469.     ld l,(hl)
  1470.     ld h,a
  1471.     add hl,de
  1472.     ex de,hl
  1473.     ld hl,(71*256)+6
  1474.     add hl,de
  1475.     ex de,hl
  1476.     ld a,2
  1477.     bcall(_mos_filledrectangle)
  1478.     ret
  1479. ;---------------------------------
  1480. ; dbfMenu_GetNextItem
  1481. ; Inputs:
  1482. ;      hl=first byte of substring
  1483. ; Outputs:
  1484. ;      hl=first byte of next substr
  1485. ;      de=length of substr, incl
  1486. ;         tCrossIcon delimiter
  1487. dbfMenu_GetNextItem:
  1488.     ld de,0
  1489. dbfMenu_GetNextLoop:
  1490.     ld a,(hl)
  1491.     inc hl
  1492.     inc de
  1493.     or a                                ;zero term
  1494.     ret z
  1495.     cp $80
  1496.     ret z                               ;tCrossIcon
  1497.     bcall(_IsA2ByteTok)
  1498.     jr nz,$+4
  1499.     inc hl
  1500.     inc de
  1501.     jr dbfMenu_GetNextLoop
  1502. ;================================
  1503. dbfPushAns:
  1504.     bcall(_RclAns)
  1505.     ld hl,Op1
  1506.     ld a,(hl)
  1507.     and $1f
  1508.     push af
  1509.         or a
  1510.         jr z,dbfPushAnsReal
  1511.         dec a
  1512.         jr z,dbfPushAnsRList
  1513.         dec a
  1514.         jr z,dbfPushAnsRMat
  1515.         sub 2
  1516.         jr z,dbfPushAnsString
  1517.         sub 8
  1518.         jr z,dbfPushAnsComplex
  1519.         dec a
  1520.         jp z,dbfPushAnsCList
  1521.         pop af
  1522.     jp xLibEndNoOut
  1523. dbfPushAnsReal:
  1524. ;       ld hl,Op1                       ;not necessary
  1525.         ld de,9
  1526.         jr dbfPushAnsContinue
  1527. dbfPushAnsCList:
  1528.         ex de,hl
  1529.         push hl
  1530.             ld h,b \ ld l,c
  1531.             add hl,hl               ;*2, so in the end it will be *18 + 2
  1532.             ld b,h \ ld c,l
  1533.             jr dbfPushAnsAllLists
  1534. dbfPushAnsRMat:
  1535.         ex de,hl
  1536.         push hl
  1537.             ld e,(hl)
  1538.             inc hl
  1539.             ld h,(hl)
  1540. ;           ld h,b \ ld e,c
  1541.             bcall(_mos_MultHE)      ;result in hl
  1542.             ld b,h \ ld c,l         ;hl->bc
  1543.             jr dbfPushAnsAllLists   ;and Mats!
  1544. dbfPushAnsRList:
  1545.         ex de,hl
  1546.         push hl
  1547.             ld h,b \ ld l,c         ;element count was in bc
  1548. dbfPushAnsAllLists:                 ;REAL   ;CPLX
  1549.             add hl,hl               ;*2     ;*4
  1550.             add hl,hl               ;*4     ;*8
  1551.             add hl,hl               ;*8     ;*16
  1552.             add hl,bc               ;*9     ;*18
  1553.             inc hl
  1554.             inc hl                  ;*9+2   ;*18+2      (because of element number count, 1 word)
  1555.             pop de
  1556.         ex de,hl                    ;hl=where, de=size
  1557.         jr dbfPushAnsContinue
  1558. dbfPushAnsString:
  1559.         ex de,hl
  1560.         ld e,(hl)
  1561.         inc hl
  1562.         ld d,(hl)
  1563.         inc hl
  1564.         jr dbfPushAnsContinue
  1565. dbfPushAnsComplex:
  1566. ;       ld hl,Op1                       ;not necessary
  1567.         ld de,18
  1568. dbfPushAnsContinue:
  1569.         push hl
  1570.             push de
  1571.                 inc de
  1572.                 inc de
  1573.                 inc de
  1574.                 push de
  1575.                     bcall(_Op1ToOp3)
  1576.                     call dbfPushPopAnsStack_AnsNameOrDefault
  1577.                     bcall(_Chkfindsym)
  1578.                     jr nc,dbfPushAnsExists
  1579.                     bcall(_Op2ToOp5)
  1580.                     pop hl
  1581.                 bcall(_CreateAppVar)
  1582.                 push de
  1583.                     bcall(_Op5ToOp2)
  1584.                     pop de
  1585.                 inc de
  1586.                 inc de
  1587.                 jr dbfPushAnsContinue2
  1588. dbfPushAnsExists:
  1589.                     pop hl
  1590.                 push hl
  1591.                     push de
  1592.                         ex de,hl
  1593.                         ld a,(hl)
  1594.                         inc hl
  1595.                         ld h,(hl)
  1596.                         ld l,a
  1597.                         add hl,de
  1598.                         pop de
  1599.                     ld a,l
  1600.                     ld (de),a
  1601.                     inc de
  1602.                     ld a,h
  1603.                     ld (de),a
  1604.                     inc de
  1605.                     pop hl
  1606.                 bcall(_InsertMem)
  1607. dbfPushAnsContinue2:
  1608.                 push de
  1609.                     bcall(_Op3ToOp1)
  1610.                     pop de
  1611.                 pop bc
  1612.             pop hl
  1613.         pop af
  1614.     ld (de),a
  1615.     inc de
  1616.     ld a,c
  1617.     ld (de),a
  1618.     inc de
  1619.     ld a,b
  1620.     ld (de),a
  1621.     inc de
  1622.     ld a,b
  1623.     or c
  1624.     jr z,dbfPushAnsFinishNoLDIR     ;added for the zero-length string case
  1625.     ldir
  1626. dbfPushAnsFinishNoLDIR:
  1627.     jp xLibEndNoOut
  1628. ;================================
  1629. dbfPopAns:
  1630.     call dbfPushPopAnsStack_AnsNameOrDefault
  1631.     bcall(_chkfindsym)
  1632.     jp c,xLibEndNoOut                   ;don't do anything if the appvar doesn't exist
  1633.     ex de,hl
  1634.     push hl
  1635.         inc hl
  1636.         inc hl
  1637.         ld a,(hl)
  1638.         inc hl
  1639.         ld e,(hl)
  1640.         inc hl
  1641.         ld d,(hl)
  1642.         push de
  1643.             ld bc,dbfPopAnsFinish
  1644.             push bc
  1645.                 inc hl                          ;item starting at hl, size in de, type in a
  1646.                 and $1f
  1647.                 or a
  1648.                 jr z,dbfPopAnsReal
  1649.                 dec a
  1650.                 jr z,dbfPopAnsRList
  1651.                 dec a
  1652.                 jr z,dbfPopAnsRMat
  1653.                 sub 2
  1654.                 jr z,dbfPopAnsString
  1655.                 sub 8
  1656.                 jr z,dbfPopAnsComplex
  1657.                 dec a
  1658.                 jr z,dbfPopAnsCList
  1659.                 pop bc
  1660. dbfPopAnsFinish:
  1661.             pop de
  1662.         pop hl
  1663.     ;need to remove de+3 bytes at hl
  1664. ;   push hl
  1665. ;       dec hl
  1666.         ld c,(hl)
  1667.         inc hl
  1668. ;       dec hl
  1669.         ld b,(hl)
  1670.         inc hl
  1671. ;       pop hl
  1672.     ex de,hl        ;de=remove from here, hl=size of entry-3, bc=size of appvar
  1673.     inc hl
  1674.     inc hl
  1675.     inc hl
  1676.     push hl
  1677.         or a
  1678.         sbc hl,bc
  1679.         pop hl
  1680.     jr nz,dbfPopAnsFinishRemove
  1681.     call dbfPushPopAnsStack_AnsNameOrDefault
  1682.     bcall(_ChkFindSym)
  1683.     bcall(_DelVar)
  1684.     jr dbfPopAnsFinishEnd
  1685. dbfPopAnsFinishRemove:
  1686.     ex de,hl                            ;hl=remove from here, de=size
  1687.     push bc
  1688.         push hl
  1689.             push de
  1690.                 bcall(_DelMem)
  1691.                 pop bc
  1692.             pop de
  1693.         pop hl
  1694.     or a
  1695.     sbc hl,bc
  1696.     ex de,hl
  1697.     dec hl
  1698.     ld (hl),d
  1699.     dec hl
  1700.     ld (hl),e
  1701. dbfPopAnsFinishEnd:
  1702.     bcall(_Op4ToOp1)                    ;goes into Ans
  1703.     ret
  1704. ;================================
  1705. dbfPopAnsReal:
  1706.     ld bc,9
  1707.     jr dbfPopAnsComplexGo
  1708. dbfPopAnsComplex:
  1709.     ld bc,18
  1710. dbfPopAnsComplexGo:
  1711.     ld de,Op1
  1712.     ldir
  1713.     bcall(_Op1ToOp4)                    ;in case ChkFindSym \ DelVar runs
  1714.     ret
  1715. dbfPopAnsRMat:
  1716.     push de
  1717.         ld e,(hl)
  1718.         inc hl
  1719.         ld d,(hl)
  1720.         inc hl
  1721.         push hl
  1722.             ex de,hl                    ;h=rows, l=columns
  1723.             bcall(_CreateTempRMat)
  1724.             jr dbfPopAnsListFinish
  1725. dbfPopAnsCList:
  1726.     push de
  1727.         ld e,(hl)
  1728.         inc hl
  1729.         ld d,(hl)
  1730.         inc hl
  1731.         push hl
  1732.             ex de,hl
  1733.             bcall(_CreateTempCList)
  1734.             jr dbfPopAnsListFinish
  1735. dbfPopAnsRList:
  1736.     push de
  1737.         ld e,(hl)
  1738.         inc hl
  1739.         ld d,(hl)
  1740.         inc hl
  1741.         push hl
  1742.             ex de,hl
  1743.             bcall(_CreateTempRList)
  1744. dbfPopAnsListFinish:
  1745.             pop hl
  1746.         inc de
  1747.         inc de
  1748.         pop bc
  1749.     dec bc
  1750.     dec bc
  1751.     ldir
  1752.     ret                                 ;name is already in Op4
  1753. dbfPopAnsString:
  1754.     push hl
  1755.         push de
  1756.             ex de,hl
  1757.             bcall(_CreateTempString)
  1758.             inc de
  1759.             inc de
  1760.             pop bc
  1761.         pop hl
  1762.     ld a,b
  1763.     or c
  1764.     ret z                               ;account for the zero-length case
  1765.     ldir
  1766.     ret                                 ;name is already in Op4
  1767. ;================================
  1768. dbfPushPopAnsStack_AnsNameOrDefault:
  1769.     ld a,(nargs)
  1770.     dec a
  1771.     jr z,dbfPushPopAnsStack_AnsDefault
  1772.     ld a,(var1)
  1773.     jp dbfAnsStackNameToOp1
  1774. dbfPushPopAnsStack_AnsDefault:
  1775.     xor a
  1776.     jp dbfAnsStackNameToOp1
  1777. ;================================
  1778. dbfClearAnsStack:
  1779.     ld hl,xLibEndNoOut
  1780.     push hl
  1781.         ld a,(nargs)
  1782. dbfClearAnsStack_OffPage:
  1783.         dec a
  1784.         jr z,dbfClearAnsStackAll
  1785.         ld a,(var1)
  1786.         call dbfAnsStackNameToOp1
  1787.         bcall(_chkfindsym)
  1788.         ret c
  1789.         bcall(_delvararc)
  1790.         ret
  1791. dbfClearAnsStackAll:
  1792.         xor a
  1793. dbfClearAnsStackLoop:
  1794.         push af
  1795.             call dbfAnsStackNameToOp1
  1796.             bcall(_chkfindsym)
  1797.             bcallnc(_delvararc)
  1798.             pop af
  1799.             inc a
  1800.         cp 10d                  ;0-9 cleared
  1801.         ret z
  1802.         jr dbfClearAnsStackLoop
  1803. dbfAnsStackNameToOp1:
  1804.         push af
  1805.             ld hl,AnsAppVar
  1806.             rst 20h
  1807.             pop af
  1808.         add a,'0'
  1809.         ld (Op1+4),a                ;'15h' 'A' 'n' 's' 'N' '\0'
  1810.         ret
  1811. ;================================
  1812. AtoRealAtHL:
  1813.     push de
  1814.         push bc
  1815.             push hl
  1816.                 bcall(_setxxop1)
  1817.                 pop de
  1818.             ld hl,Op1
  1819.             ld bc,9
  1820.             ldir
  1821.             pop bc
  1822.         pop hl
  1823.     ex de,hl
  1824.     ret
  1825. ;================================
  1826. Get_Strng_Tok:
  1827.     push bc
  1828.         ld h,0
  1829.         ld l,a
  1830.         cp $30                          ;'0'
  1831.         jr c,Get_Strng_Tok_NotNum
  1832.         cp $39+1
  1833.         jr c,Get_Strng_Tok_Fin          ;'0' to '9'
  1834. Get_Strng_Tok_NotNum:
  1835.         cp $41                          ;'A'
  1836.         jr c,Get_Strng_Tok_NotLetUpr
  1837.         cp $5A+1
  1838.         jr c,Get_Strng_Tok_Fin          ;'A' to 'Z'
  1839. Get_Strng_Tok_NotLetUpr:
  1840.         cp $61
  1841.         jr c,Get_Strng_Tok_NotLetLwr
  1842.         cp $7A+1
  1843.         jr nc,Get_Strng_Tok_NotLetLwr
  1844.         ld h,$BB
  1845.         add a,$B0-$61
  1846.         ld l,a
  1847.         cp $BB
  1848.         jr c,Get_Strng_Tok_Fin
  1849.         inc l
  1850.         jr Get_Strng_Tok_Fin
  1851. Get_Strng_Tok_NotLetLwr:
  1852.         ld b,(Get_Strng_Tok_TblTwoByteEnd-Get_Strng_Tok_TblTwoByte)/2
  1853.         ld hl,Get_Strng_Tok_TblTwoByte
  1854. Get_Strng_Tok_TwoByteLoop:
  1855.         ld c,(hl)
  1856.         inc hl
  1857.         cp c
  1858.         jr z,Get_Strng_Tok_TwoByteFinish
  1859.         inc hl
  1860.         djnz Get_Strng_Tok_TwoByteLoop
  1861.         ld b,(Get_Strng_Tok_TblOneByteEnd-Get_Strng_Tok_TblOneByte)/2
  1862.         ld hl,Get_Strng_Tok_TblOneByte
  1863. Get_Strng_Tok_OneByteLoop:
  1864.         ld c,(hl)
  1865.         inc hl
  1866.         cp c
  1867.         jr z,Get_Strng_Tok_OneByteFinish
  1868.         inc hl
  1869.         djnz Get_Strng_Tok_OneByteLoop
  1870.         ld hl,$000E
  1871. Get_Strng_Tok_Fin:
  1872.         ld a,h
  1873.         or a
  1874.         pop bc
  1875.     ret
  1876. Get_Strng_Tok_TwoByteFinish:
  1877.         ld l,(hl)
  1878.         ld h,$BB
  1879.         jr Get_Strng_Tok_Fin
  1880. Get_Strng_Tok_OneByteFinish:
  1881.         ld l,(hl)
  1882.         ld h,0
  1883.         jr Get_Strng_Tok_Fin
  1884.  
  1885. Get_Strng_Tok_TblTwoByte:
  1886.     .db $05,$EC
  1887.     .db $09,$F1
  1888.     .db $23,$D2
  1889.     .db $24,$D3
  1890.     .db $25,$DA
  1891.     .db $26,$D4
  1892.     .db $27,$D0
  1893.     .db $B6,$9A
  1894.     .db $B7,$9B
  1895. Get_Strng_Tok_TblTwoByteEnd:
  1896.  
  1897. Get_Strng_Tok_TblOneByte:
  1898.     .db $1A,$B0
  1899.     .db $20,$29
  1900.     .db $21,$2D
  1901.     .db $22,$2A
  1902.     .db $28,$10
  1903.     .db $29,$11
  1904.     .db $2A,$82
  1905.     .db $2B,$70
  1906.     .db $2C,$2B
  1907.     .db $2E,$3A
  1908.     .db $2F,$83
  1909.     .db $3a,$3E
  1910.     .db $3F,$D6
  1911.     .db $5D,$07
  1912.     .db $5E,$F0
  1913.     .db $5F,$D9
  1914.     .db $C1,$06
  1915.     .db $D6,$81
  1916. Get_Strng_Tok_TblOneByteEnd:
  1917.  
  1918. ;==============================================
  1919.  
  1920. #define  Cn2_Setup          $4209
  1921. #define  Cn2_Clear_SendBuf  $420C
  1922. #define  Cn2_Clear_RecBuf   $420F
  1923. #define Cn2_Setdown         $4212
  1924. #define Cn2_GetK            $4221
  1925. #define SWord               $87FF
  1926. #define Rword               $86F8
  1927. #define Sdat                $8801
  1928. #define Rdat                $86FA
  1929. #define rvarlength          $9872+176   ; put at the end of appbackupscreen right after iambians variable only because idk what he is doing there so best safe then sorry
  1930. dbfCn2BASICSend:            ;INCOMPLETE
  1931. ;Check arguments
  1932. ; order is
  1933. ; ID
  1934. ; Data
  1935. ; ID is any real variable preferably theta for simplicities sake
  1936. ; Data can be a string of a list. gonna have to parse the vat for just the type and put a 1/0 in for type
  1937. ; after thats parsed its a simple copy of the real to the ip part
  1938. ; the size is copied from the data pointer
  1939. ; for lists its (multx9)+1
  1940. ; for strings its length+1
  1941.  
  1942. ;   Order of stuff
  1943. ; Check for pending frame if one quit early (send status code?)
  1944. ; Set up buffers
  1945. ; set up sizes
  1946. ; mark pending
  1947. ; set ans to 1 if frame was set to 0 if not
  1948. ; quit
  1949. ; jp $
  1950.  ld a,(sword+1) ; load a with the frame pending flag byte
  1951.  bit 7,a             ; if the msb is set we have a frame
  1952.  jp nz,QUITBAD  
  1953.  ; Assumign theta for The real var removing from wiki now 2/7/13
  1954.  ld hl,IDRealName
  1955.  rst 20h
  1956.  bcall(_chkfindsym)  
  1957.  jp c,QUITBAD        ; make suer theta exists
  1958.  xor a
  1959.  cp b
  1960.  jp nz,QUITBAD     ; if file is in atchive quit cause im to lazy to unarchive it. Who archives realvars anyway? delvar that shit
  1961.  inc de \ inc de ; Load to the actual data we want not the realvar exponent/flagbytes
  1962.  ex de,hl         ; move data pointer to hl for Ldir
  1963.  ld de,$87fa  
  1964.  ld bc,5
  1965.  ldir            ; copy bytes into Id
  1966.  
  1967.  
  1968.  ld hl,sc1       ; load Op1 value of passed data
  1969.  rst 20h
  1970.  bcall(_chkfindsym)
  1971.  jp c,QUITBAD
  1972.  ld c,a
  1973.  xor a
  1974.  cp b
  1975.  jp nz,QUITBAD
  1976.  ex de,hl
  1977.  ld a,c
  1978.  and 1fh        ; A contains the element type in the lower 5 bits mask out the upper bits
  1979.  cp 4           ; if its a string
  1980.  jr z,SString   ; ...
  1981.  cp 1           ; if its a list
  1982.  jr z,SList     ; ...
  1983.  jp QuitBad     ; if none of the above skedadle
  1984.  
  1985. SString:       ;Set (frame) to 0 ; Also get size from list and +3 to it for frame length
  1986.  ld a,0
  1987.  ld de,sdat    ; overwrite vat pointer (lol who uses those) with sdat
  1988.  ld (de),a     ; load first byte of frame with 0
  1989.  inc de
  1990.  ld c,(hl)
  1991.  inc hl
  1992.  ld b,(hl)    ; load hl with the size of the string.
  1993.  dec hl       ; return hl to start of the string
  1994.  inc bc
  1995.  inc bc
  1996.  inc bc      ; increase it to match size+info byte length
  1997.  ld (sword),bc ; save to length proper
  1998.  dec bc  ; restore size after we increase it to match size+ length bytes
  1999.  ldir
  2000.  ld a,0
  2001.  bcall(_setxxop1)
  2002.  ld a,(sword+1)
  2003.  or 80h
  2004.  ld (sword+1),a
  2005.  ret
  2006.  
  2007.  
  2008. SList:        ; Set (frame) to 1
  2009.  ld a,1
  2010.  ld de,sdat    ; overwrite vat pointer (lol who uses those) with sdat
  2011.  ld (de),a     ; load first byte of frame with 1
  2012.  inc de
  2013.  ld c,(hl)  ; dont need the whole thing as this can not be over 28              
  2014.   ld a,c    ; and while yes this can leave a bug if there is over 100 elements in the list not my problem
  2015.   cp 29      
  2016.   jr nc,QUITBAD   ; quit if over 28
  2017.   add a,a
  2018.   add a,a
  2019.   add a,a
  2020.   add a,c   ; multiply by nine
  2021.   inc a    
  2022.   inc a     ; increase a by 3 for when we
  2023.   inc a     ; to accomodate for info byte and size bytes of variable
  2024.   ld (sword),a
  2025.   dec a     ; return to var size
  2026.   ld b,0    ; make bc 00xx where xx will be C
  2027.   ld c,a    ; save to C so we have 00xx proper
  2028.  ; hl = var data
  2029.  ; bc = length of var.
  2030.  ; de = cn2 buffer
  2031.  ldir       ;
  2032.  ld a,0
  2033.  bcall(_setxxop1)
  2034.   ld a,(sword+1)
  2035.  or 80h
  2036.  ld (sword+1),a
  2037.  ret
  2038. dbfCn2BASICGet:             ;INCOMPLETE
  2039. ; Check to see if there is a frame.
  2040. ; if there is parse the frame and write out
  2041. ; id gets copied into the String
  2042. ; List gets copied into the list
  2043.  
  2044.  
  2045. ; we are sending raw variable data in the frames
  2046. ; So if it is a list add it to a list if it is a string add it to a string
  2047. ; MAKE SURE WE HAVE ENOUGH Ram for this
  2048.  
  2049. ;Order of routine.
  2050. ;   Check for pending frame  [x]
  2051. ;   MTROC ID string8    
  2052. ;   Copy ID over
  2053. ;   Check Data Type
  2054. ;   MTROC Appropriate variable  (LCn2,Str9)
  2055. ;   Copy Data over
  2056. ;   Clear Frame Pending
  2057. ;   Ret
  2058. ; set ans to 0 if frame was recieved
  2059.  
  2060.  ld a,(rword+1) ; load a with the incoming flag byte
  2061.  bit 7,a             ; if the msb is set we have a frame
  2062.  jp z,QUITBAD               ; if its not quit
  2063.  ld hl,IDrealName
  2064.  ld a,1                  ;delete and create theta.
  2065.  ld (RVarLength),a
  2066.  call DeleteAndCreate
  2067.  push de                ; save data pointer so we can write the id to it later
  2068.   ld a,(rdat)          ; load a with frame id
  2069.   or a    ;if 0 we have a string if one we have a list.
  2070.   jp nz,ldlist          ; if list div length by nine
  2071.   ld a,(Rword)
  2072.   sub 1                 ; if string calculate length
  2073.   ld (RVarLength),a
  2074.   ld hl,DataStringName
  2075.   jr Copydata
  2076. ;kinda just shoved this here. Makes following it a pain but do I really care?
  2077. ; nothing traverses here it all jumps over it. Woo dead space
  2078.  
  2079. QUITBAD:
  2080.  ;returns 1 if we failed. reusable routine.
  2081.  ld a,1
  2082.  bcall(_setxxop1)
  2083.  ret  
  2084.  
  2085. ldlist:
  2086.   ld a,(rword)
  2087.   dec a
  2088.   ld b,0
  2089. Div9Loop:
  2090.   inc b
  2091.   sub 9
  2092.   jr z,Div9Done
  2093.   jr nc,div9loop
  2094. Div9Done:
  2095.   ld a,b
  2096.   ld (RVarLEngth),a
  2097.   ld hl,DataListName
  2098.  
  2099.  
  2100. CopyData:
  2101.   Call DeleteAndCreate
  2102.   ;get data length -1 -> bc
  2103.   ld a,(rword)      ; get length from frame and store into bc
  2104.   dec a
  2105.   ld c,a
  2106.   ld b,0
  2107.   ld hl,(rdat+1)    ; load hl with pointer to frame+1 for variable data
  2108.   ldir
  2109.  pop de
  2110. ;here i handle the real this should be rather easy
  2111. ;we are interested in just the first 5 values in the mantessa
  2112. ; the mantessa is de+2
  2113. ; so lets initialise our variable
  2114.  ld hl,$0080     ;standard exponent and no negative? i think we will see
  2115.  inc de \ inc de
  2116. ;Now the next 5 bytes are our id.
  2117.  ld bc,5
  2118.  ld hl,($86F3)   ; recieve id
  2119.  ldir
  2120. ;theta now has the user id in it
  2121.  ld hl,RWord+1
  2122.  res 7,(hl)
  2123.  ; aknowledge we got a frame and quit
  2124.  ld a,0
  2125.  bcall(_setxxop1)
  2126.  ret
  2127.  ;according to iambian and some of kerms code this is supposed to return the value of op1 in ans �\(�_o)/�
  2128.  ; jp XlibEndNoOut
  2129. DeleteAndCreate
  2130. ;expects pointer to variable name in hl
  2131. ;destroys all
  2132. ;returns pointer to variable data in de
  2133.  push hl
  2134.   rst 20h  ;load op1 with variable name
  2135.   bcall(_chkfindsym)
  2136.   jr c,create
  2137.   ld hl,op1             ; I belive i need to do this for delvararc.
  2138.   bcall(_DelVarArc)   ;delete if since it exists
  2139. Create:
  2140.  pop hl
  2141.  ld a,(hl)
  2142.  ld hl,(RVarLength)
  2143.  bcall(_createvar)
  2144.  ret
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150. DataStringName:
  2151.  .db strngOBJ,tVarStrng,tstr9,$0
  2152. IDRealName:
  2153.  .db $0,tTheta,$0,$0
  2154. DataListName:
  2155.  .db $01,tVarLst,tC,tN,t2,$0
  2156.  
  2157. dbfCn2BASICStop:                ;Main Functions Complete
  2158.  ld a,(nargs)
  2159.  cp 2
  2160.  jp nz,xLIBEndNoOut
  2161.  ld A,(var1)
  2162.  cp 1
  2163.  jr z,enablecn2    ; If enabled, skip over enabling
  2164.  jp disablecn2
  2165.  
  2166. EnableCn2:
  2167. ;Disable APD Setup Cn2.2 Hook TiOs intterupt.
  2168.  
  2169.  bcall(4C84h)            ;Disable APD  ( DO we even use ti83+.inc???
  2170.  ;jp $
  2171.  di
  2172.  bcall(_Cn3_Setup)
  2173.  ld hl,0038
  2174.  ld (Cn2_Hook_Pre),HL   ; Hopefully chain The tios intterupt before the calcnet intterupt.
  2175.                           ; Personally wondering if this should be at the end of the calcnet intterupt.
  2176.                           ; only because of how the tios intterupt is unpredicable in length.
  2177.                           ; Do we really have to worry about that?? According to kerm I do not
  2178.  
  2179.  set 3,(iy+33h)           ; ignoreBPlink          
  2180.  res 4,(iy+33h)           ; BPLinkOn      Disable link Assist for sure
  2181.  res 0,(iy+3Eh)           ;                Disables Silent linking supposedly  
  2182.  ld a,%00000001
  2183.  out (08),a               ;Disable link assist via ports want as much cushion as possible here.
  2184.  ei
  2185.  jp xLIBEndNoOut
  2186.  
  2187. DisableCn2:
  2188.  
  2189.  bcall(_Cn3_Setdown)
  2190.  di
  2191.  res 3,(iy+33h)           ; ignoreBPlink          
  2192.  set 4,(iy+33h)           ; BPLinkOn      Enable Silent linking and link assist
  2193.  set 0,(iy+3Eh)  
  2194.  ld a,0
  2195.  out (08),a               ; Reenable link assist disable intterupts
  2196.  bcall($4C87)              ; Enable Apd again
  2197.  ei
  2198.  jp xLibEndNoOut
Advertisement
Add Comment
Please, Sign In to add comment