home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / zshell / 3dview.asm next >
Encoding:
Assembly Source File  |  2001-07-01  |  25.1 KB  |  1,117 lines

  1. #include "ti-85.h"                      ;header file that contains macros
  2. .org 0                                  ;sets program counter to 0
  3. .db "3DViewer v1.5 by Alan B.",0        ;the name
  4.  
  5.  
  6.  
  7. BEGXCOORD  =     $80DF      
  8. XCOORD  =        $80E0 ;\keep these two together, okay
  9. YCOORD  =        $80E1 ;/
  10. GRAPHMEM  =      $80E4
  11. GRAM1  =         $80E6
  12. GRAM2  =         $80E8
  13. WHICHGRAM  =     $80EA     ;0,1,2
  14. OFFSET  =        $80ED
  15. BITNUM  =        $80EF
  16. DEPTH  =         $80F0
  17. RANDNUM  =       $80F1
  18. RANDBIT  =       $80F2
  19. NAMEBUFFER =     $80F3   ;8 bytes
  20. COUNTER =        $80FB
  21. MEMFREE =        $80FC
  22. CURSGRAM1 =      $80FD    ;\keep these two together, okay
  23. CURSGRAM2 =      $80FE    ;/
  24. STEREOIND =      $80FF  ;\keep these two together, okay
  25. MAXIND =          $8100    ;/
  26. BOXDEPTH =       $8101
  27. BOXTOP =         $8102  ;y varialbe of top of box
  28.  
  29.  
  30. ;++++++++++++++++++++++++++++
  31. ;++Editing screen variables++
  32. ;++++++++++++++++++++++++++++
  33. ;XCOORD=x coordinate in editing screen [0-127] (byte)*     
  34. ;YCOORD=y coordinate in editing screen [0-63] (byte)*
  35. ;GRAM1=address in program for stereogram1 [wherever in mem] (word)* 
  36. ;GRAM2=address in program for stereogram2 [right after stereogram1] (word)*
  37. ;WHICHGRAM=address that is being used [1 or 2] (byte)*
  38. ;OFFSET=offset of pixel in memory [0-896] (word)*          
  39.  
  40. ;++++++++++++++++++++++++++++
  41. ;++Viewing screen variables++
  42. ;++++++++++++++++++++++++++++
  43. ;BEGXCOORD=beginning x coordinate in viewing screen [0-15] (byte)*
  44. ;XCOORD=movable x coordinate in viewing screen [0-127] (byte)*
  45. ;YCOORD=y coordinate in viewing screen [0-63] (byte)*
  46. ;GRAPHMEM=place in graphics memory to store [$8641-$8A41] (word)*
  47. ;OFFSET=offset in both stereogram1 and 2 [0-896] (word)*
  48. ;BITNUM=value to check in stereogram1 and 2 [1,2,4,8,16,32,64,128] (byte)*
  49. ;DEPTH=depth of the next pixel to place [14-16] (byte)*
  50. ;RANDNUM=random pointer used to get random number [0-21] (byte)*
  51. ;RANDBIT=random number [0 or 1] (byte)*
  52.  
  53.  
  54.  
  55.     ld hl,ZS_BITS           ;this sets bit 0 of ZS_BITS
  56.     set 0,(hl)              ;do this if you store any variables
  57.     ld a,4                  ;so that FIND_PIXEL routine can
  58.     out (5),a               ;be used later
  59.     ld hl,($8BE5)
  60.     ld de,($8BE1)
  61.     or a
  62.     sbc hl,de
  63.     ld a,h
  64.     and %11111000
  65.     or a
  66.     ld (MEMFREE),a
  67.     jr z,screen
  68.     ld hl,($8BE1)        ;now so if it's ever used, it's there    temp stereogram
  69.     ld de,($8BE1)
  70.     inc de
  71.     ld a,0
  72.     ld b,128
  73. makenewstereo2:
  74.     push bc
  75.     ld (hl),a
  76.     ld bc,13
  77.     ldir
  78.     ld a,$C0
  79.     ld (de),a
  80.     ld a,$00
  81.     inc de
  82.     ld (de),a
  83.     inc de
  84.     push de
  85.     pop hl
  86.     inc de
  87.     pop bc
  88.     sub a
  89.     ld (STEREOIND),a
  90.     djnz makenewstereo2
  91.  
  92. ;++++++++++++++++++++++++++++++++++++
  93. ;++++++++++++++++++++++++++++++++++++
  94. ;++This displays the opening screen++
  95. ;++++++++++++++++++++++++++++++++++++
  96. ;++++++++++++++++++++++++++++++++++++
  97. screen:
  98.     ld a,r                            ;this is all a litle mixup for the random table
  99.     and %00011110                ;contains number 0-30
  100.     ld c,a
  101.     ld b,0
  102.     ld hl,(PROGRAM_ADDR)    ;\
  103.     ld de,rnumbers         ; }get this thing again
  104.     add hl,de               ;/
  105.     add hl,bc            ;puts an offset in it so it's really random
  106.     ld c,(hl)               ;c holds first one
  107. startrandom2:
  108.     inc hl                  ;this routine moves all the bytes 
  109.     ld b,(hl)               ;one byte to the left
  110.     dec hl                  ;I'm not gonna explain it all
  111.     ld (hl),b
  112.     inc hl
  113.     inc hl
  114.     ld a,(hl)
  115.     cp $FF
  116.     jr startrandom3
  117.     dec hl
  118.     jr startrandom2
  119. startrandom3:
  120.     dec hl
  121.     ld (hl),c               ;c is put in last spot------------------\
  122.  
  123.     ROM_CALL(CLEARLCD)      ;CLEAR
  124.     ld hl,(PROGRAM_ADDR)    ;\
  125.     ld de,graphic           ; }this finds the graphic "3D"
  126.     add hl,de               ;/
  127.     ld de,$FC20             ;this is where we want it to appear
  128.     ld bc,$0004             ;the byte counter for ldir
  129. putgraphic:
  130.     ldir                    ;ldir-loads hl to de until bc=0
  131.     ex de,hl                ;exchange contents cause changing de
  132.     ld bc,$000C             ;add 13 so it's at the next line
  133.     add hl,bc               ;in video memory
  134.     ex de,hl                ;switch them back
  135.     ld a,e                  ;so we can compare to see if
  136.     cp $F0                  ;it is all done
  137.     JUMP_Z(lineundertitle)  ;if so, go there
  138.     ld bc,$0004             ;if not, set byte counter and go back
  139.     JUMP_(putgraphic)       ;to the beginning of the loop
  140. lineundertitle:
  141.     ld hl,$FD20             ;this is the place we want to put line
  142.     ld a,$FF                ;FFh=11111111b, bitmap
  143.     ld (hl),a
  144.     ld de,$FD21
  145.     ld bc,15
  146.     ldir
  147.  
  148.     ld hl,$FD20
  149.     ld de,$FF64
  150.     ld bc,12
  151.     ldir
  152.  
  153.     ld a,%10000000
  154.     ld hl,$FF74
  155.     ld b,9
  156.     ld de,$0010
  157. lineundertitle2:
  158.     ld (hl),a
  159.     add hl,de
  160.     djnz lineundertitle2
  161.  
  162.     ld a,%00000010
  163.     ld hl,$FC08
  164.     ld b,18
  165.     ld de,$0010
  166. lineundertitle3:
  167.     ld (hl),a
  168.     add hl,de
  169.     djnz lineundertitle3
  170.  
  171. words:
  172.     ld bc,$0501             ;this is the place we want to display
  173.     ld ($800C),bc           ; _x_y in order in ($800C)
  174.     ld hl,(PROGRAM_ADDR)    ;
  175.     ld de,title             ;you've seen this before
  176.     add hl,de
  177.     ROM_CALL(D_ZT_STR)      ;this displays the phrase
  178.     ld bc,$014B
  179.     ld ($8333),bc
  180.     ROM_CALL(D_ZM_STR)
  181.     push hl
  182.     ld a,(STEREOIND)
  183.     push af
  184.     CALL_(findstereos)
  185.     pop af
  186.     ld (STEREOIND),a
  187.     CALL_(showstereoname)
  188.     pop hl
  189.     ld bc,$1526             ;coordinates
  190.     ld ($8333),bc           ;into the menutext cursor ($8333)
  191.     ROM_CALL(D_ZM_STR)      ;display menutext
  192.     ld bc,$0304             ;same
  193.     ld ($800C),bc           ;same
  194.     ROM_CALL(D_ZT_STR)      ;\/
  195.     ld bc,$2B16
  196.     ld ($8333),bc
  197.     ROM_CALL(D_ZM_STR)
  198.     ld bc,$3829             ;\/
  199.     ld ($8333),bc           ;\/
  200.     ROM_CALL(D_ZM_STR)      ;\/
  201.     ld a,
  202. waitforkey:
  203.     call GET_KEY            ;checks keystroke
  204.     cp K_RIGHT
  205.     JUMP_Z(changestereor)
  206.     cp K_LEFT
  207.     JUMP_Z(changestereol)
  208.     cp K_F1                 ;goes to
  209.     JUMP_Z(makepicture)     ;makepicture
  210.     cp K_F2                 ;or
  211.     JUMP_Z(viewpicture)     ;viewpicture
  212.     cp K_F3                 ;No, No...
  213.     ret z                   ;don't leave
  214.     cp K_EXIT               ;exit and f3 do the same thing
  215.     ret z
  216.     JUMP_(waitforkey)       ;gives them another chance
  217.  
  218.  
  219. changestereor:
  220.     ld hl,(STEREOIND)            ;this gets MAXIND too
  221.     ld a,l
  222.     cp h
  223.     jr z,changer2
  224.     inc a
  225.     ld (STEREOIND),a
  226.     CALL_(showstereoname)
  227.     jr waitforkey
  228. changer2:
  229.     sub a
  230.     ld (STEREOIND),a
  231.     CALL_(showstereoname)
  232.     jr waitforkey
  233.  
  234. changestereol:
  235.     ld a,(STEREOIND)
  236.     or a
  237.     jr z,changel2
  238.     dec a
  239.     ld (STEREOIND),a
  240.     CALL_(showstereoname)
  241.     jr waitforkey
  242. changel2:
  243.     ld a,(MAXIND)
  244.     ld (STEREOIND),a
  245.     CALL_(showstereoname)
  246.     jr waitforkey
  247.     
  248.  
  249.  
  250. findstereos:
  251.     sub a
  252.     ld (STEREOIND),a
  253.     ld hl,$FA6F
  254. findstereos2:
  255.     ld de,($8BE5)
  256.     call CP_HL_DE
  257.     jr z,alldonestereos
  258.     ld a,(hl)
  259.     cp $0c
  260.     jr z,foundone
  261.     dec hl
  262.     dec hl
  263.     dec hl
  264.     ld c,(hl)
  265.     inc c
  266.     ld b,0
  267.     or a
  268.     sbc hl,bc
  269.     jr findstereos2
  270. foundone:
  271.     dec hl
  272.     ld e,(hl)
  273.     dec hl
  274.     ld d,(hl)
  275.     ex de,hl
  276.     inc hl
  277.     inc hl
  278.     inc hl
  279.     ld a,(hl)
  280.     inc hl
  281.     ld b,(hl)
  282.     add a,b
  283.     cp $77
  284.     jr z,foundone2
  285.     ex de,hl
  286.     dec hl
  287.     ld c,(hl)
  288.     inc c
  289.     ld b,0
  290.     or a
  291.     sbc hl,bc        ;hl contains next vat entry
  292.     jr findstereos2
  293. foundone2:
  294.     inc hl
  295.     dec de
  296.     push de
  297.     push hl
  298.     push de
  299.     ld a,(STEREOIND)
  300.     rlca
  301.     rlca
  302.     ld c,a
  303.     ld b,0
  304.     ld hl,(PROGRAM_ADDR)
  305.     ld de,stereodata
  306.     add hl,de
  307.     add hl,bc    
  308.     pop bc
  309.     ld (hl),c
  310.     inc hl
  311.     ld (hl),b
  312.     pop bc
  313.     inc hl
  314.     ld (hl),c
  315.     inc hl
  316.     ld (hl),b
  317.     ld hl,STEREOIND
  318.     inc (hl)
  319.     pop hl
  320.     ld c,(hl)
  321.     inc c
  322.     ld b,0
  323.     or a
  324.     sbc hl,bc            ;hl contains next vat entry
  325.     jr findstereos2
  326. alldonestereos:
  327.     ld hl,(PROGRAM_ADDR)
  328.     ld de,newstereo
  329.     add hl,de
  330.     push hl
  331.     ld a,(STEREOIND)
  332.     rlca
  333.     rlca
  334.     ld c,a
  335.     ld b,0
  336.     ld hl,(PROGRAM_ADDR)
  337.     ld de,stereodata
  338.     add hl,de
  339.     add hl,bc
  340.     pop bc
  341.     ld (hl),c
  342.     inc hl
  343.     ld (hl),b
  344.     inc hl
  345.     ld bc,($8BE1)
  346.     ld (hl),c
  347.     inc hl
  348.     ld (hl),b
  349.     ld a,(STEREOIND)
  350.     ld (MAXIND),a
  351.     ret
  352.  
  353.  
  354. showstereoname:
  355.     ld bc,$084E
  356.     ld ($8333),bc
  357.     ld a,$20
  358.     ld b,$30
  359. clearspace:
  360.     push bc
  361.     push af
  362.     ROM_CALL(M_CHARPUT)
  363.     pop af
  364.     pop bc
  365.     djnz clearspace
  366.     ld bc,$0850
  367.     ld ($8333),bc
  368.     ld a,$cf
  369.     ROM_CALL(M_CHARPUT)
  370.     ld a,(STEREOIND)
  371.     rlca
  372.     rlca
  373.     ld c,a
  374.     ld b,0
  375.     ld hl,(PROGRAM_ADDR)
  376.     ld de,stereodata
  377.     add hl,de
  378.     add hl,bc
  379.     call LD_HL_MHL
  380.     ld b,(hl)
  381.     dec hl
  382.     ld de,NAMEBUFFER
  383.     push bc
  384. showstereoname2:
  385.     ld a,(hl)
  386.     ld (de),a
  387.     dec hl
  388.     inc de
  389.     djnz showstereoname2
  390.     pop bc
  391.     ld hl,NAMEBUFFER
  392.     ROM_CALL(D_LM_STR)
  393.     ld a,$20
  394.     ROM_CALL(M_CHARPUT)
  395.     ld a,$05
  396.     ROM_CALL(M_CHARPUT)
  397.     ret
  398.  
  399.  
  400. ;+++++++++++++++++++++++++++++++++++++++++++
  401. ;+++++++++++++++++++++++++++++++++++++++++++
  402. ;++This is the start of the editing screen++
  403. ;+++++++++++++++++++++++++++++++++++++++++++
  404. ;+++++++++++++++++++++++++++++++++++++++++++
  405. makepicture:
  406.     ld a,(STEREOIND)
  407.     rlca
  408.     rlca
  409.     ld c,a
  410.     ld b,0
  411.     ld hl,(PROGRAM_ADDR)
  412.     ld de,stereodata
  413.     add hl,de
  414.     add hl,bc
  415.     inc hl
  416.     inc hl                ;now it's at address
  417.     call LD_HL_MHL
  418.     push hl            ;\puts in bc
  419.     pop bc            ;/
  420.     ld de,($8BE1)
  421.     or a
  422.     sbc hl,de
  423.     ld a,(MEMFREE)
  424.     ld e,a
  425.     ld d,0
  426.     add hl,de
  427.     ld a,l
  428.     or h
  429.     or a
  430.     JUMP_Z(nomemfornew)
  431.     push bc
  432.     pop hl
  433.     ld (GRAM1),hl
  434.     ld de,$0400
  435.     add hl,de
  436.     ld (GRAM2),hl
  437.     ld a,0                  ;the first stereogram is in use
  438.     ld (WHICHGRAM),a
  439.     ld a,$38                ;$38=56d center of screen 56*2=112 +16=128
  440.     ld (XCOORD),a           ;look at the top for the definitions
  441.     ld a,$20                ;20h=32d
  442.     ld (YCOORD),a            ;y coordinate
  443.     ld a,$70
  444.     ld (COUNTER),a
  445.     ROM_CALL(CLEARLCD)
  446.  
  447.     ld a,$88
  448.     ld hl,$8700
  449.     ld (hl),a
  450.     ld de,$8701
  451.     ld bc,$00FF
  452.     ldir
  453.  
  454.     ld hl,(PROGRAM_ADDR)
  455.     ld de,introut
  456.     add hl,de
  457.     ld de,$8888
  458.     ld bc,introutend+1-introut         
  459.     ldir
  460.  
  461.     ld a,$87
  462.     ld i,a
  463.     im 2
  464.     CALL_(putcursor)
  465.  
  466. checktheloop:   
  467.     call GET_KEY            ;CHECKS KEY FOR ALL OF THE NEXT THINGS
  468.     cp K_EXIT               ;                   \/
  469.     JUMP_Z(leave)          ;                   \/
  470.     cp K_UP
  471.     JUMP_Z(upgo)
  472.     cp K_DOWN
  473.     JUMP_Z(downgo)
  474.     cp K_LEFT
  475.     JUMP_Z(leftgo)
  476.     cp K_RIGHT
  477.     JUMP_Z(rightgo)
  478.     cp K_PLUS
  479.     JUMP_Z(upcontrast)
  480.     cp K_MINUS
  481.     JUMP_Z(downcontrast)
  482.     cp K_STAR
  483.     JUMP_Z(upcounter)
  484.     cp K_SLASH
  485.     JUMP_Z(downcounter)
  486.     cp K_F1
  487.     JUMP_Z(F1press)
  488.     cp K_F2
  489.     JUMP_Z(F2press)
  490.     cp K_F3
  491.     JUMP_Z(F3press)
  492.     cp K_F4
  493.     JUMP_Z(F4press)
  494.     cp K_CLEAR
  495.     JUMP_Z(clearall)
  496.     cp K_GRAPH
  497.     JUMP_Z(boxfill)
  498.     jr checktheloop     ;returns to check loop again
  499.  
  500. nomemfornew:
  501.     ld hl,$FC00
  502. nomemfornew2:
  503.     ld a,(hl)
  504.     cpl
  505.     ld (hl),a
  506.     inc hl
  507.     ld a,h
  508.     or l
  509.     or a
  510.     jr nz,nomemfornew2
  511.     ld hl,$0400
  512.     ld ($800C),hl
  513.     ld hl,nomemstring
  514.     ld de,(PROGRAM_ADDR)
  515.     add hl,de
  516.     ROM_CALL(D_ZT_STR)
  517.     ld b,$FF
  518. loopynomem:
  519.     halt
  520.     djnz loopynomem
  521.     JUMP_(screen)
  522.  
  523. ;+++++++++++++++++++++++++++++++++++++++++++
  524. ;++Different things to do during the cycle++
  525. ;+++++++++++++++++++++++++++++++++++++++++++
  526. upgo:
  527.     ld a,(YCOORD)            ;y coordinate
  528.     cp $3F                  ;if it's at the top, go back
  529.     JUMP_Z(checktheloop)    ;to checktheloop
  530.     push af
  531.     CALL_(removecursor)
  532.     pop af
  533.     inc a                   ;or move up
  534.     ld (YCOORD),a            ;and load the new coordinate
  535.     CALL_(putcursor)
  536.     JUMP_(checktheloop)     ;and go back
  537. downgo:
  538.     ld a,(YCOORD)            ;exactly the same, diff #'s
  539.     cp 0
  540.     JUMP_Z(checktheloop)
  541.     push af
  542.     CALL_(removecursor)
  543.     pop af
  544.     dec a
  545.     ld (YCOORD),a
  546.     CALL_(putcursor)
  547.     JUMP_(checktheloop)
  548. leftgo:
  549.     ld a,(XCOORD)            ;like I said
  550.     cp 0
  551.     JUMP_Z(checktheloop)
  552.     push af
  553.     CALL_(removecursor)
  554.     pop af
  555.     dec a
  556.     ld (XCOORD),a
  557.     CALL_(putcursor)
  558.     JUMP_(checktheloop)
  559. rightgo:                        ;again
  560.     ld a,(XCOORD)
  561.     cp $6F
  562.     JUMP_Z(checktheloop)
  563.     push af
  564.     CALL_(removecursor)
  565.     pop af
  566.     inc a
  567.     ld (XCOORD),a
  568.     CALL_(putcursor)
  569.     JUMP_(checktheloop)
  570.  
  571. upcounter:
  572.     ld a,(COUNTER)
  573.     inc a
  574.     ld (COUNTER),a
  575.     JUMP_(checktheloop)
  576.  
  577. downcounter:
  578.     ld a,(COUNTER)
  579.     dec a
  580.     ld (COUNTER),a
  581.     JUMP_(checktheloop)
  582.  
  583. leave:
  584.     im 1
  585.     CALL_(removecursor)
  586.     JUMP_(screen)
  587.  
  588. upcontrast:
  589.     ld a,($8007)            ;$8007 is current contrast
  590.     inc a                   ;move up two, will move down one later
  591.     inc a
  592.     ld ($8007),a            ;load into current contrast
  593.     out (2),a               ;and the port
  594. downcontrast:                   ;;;the upcontrast continues through here
  595.     ld a,($8007)            ;gets current contrast
  596.     dec a                   ;moves down one
  597.     ld ($8007),a            ;and moves back into address
  598.     out (2),a               ;and port
  599.     JUMP_(checktheloop)     ;go back
  600.             ;you can't read from port 2
  601.             ;if you just try moveing up one, it don't go
  602. clearall:
  603.     ld hl,(GRAM1)
  604.     ld de,(GRAM1)
  605.     inc de
  606.     ld a,0
  607.     ld b,128
  608. clearall2:
  609.     push bc
  610.     ld (hl),a
  611.     ld bc,13
  612.     ldir
  613.     ld a,$C0
  614.     ld (de),a
  615.     sub a
  616.     inc de
  617.     ld (de),a
  618.     inc de
  619.     push de
  620.     pop hl
  621.     inc de
  622.     pop bc
  623.     djnz clearall2
  624.     ld hl,$0000
  625.     ld (CURSGRAM1),hl
  626.     CALL_(putcursor)
  627.     JUMP_(checktheloop)
  628.  
  629. F1press:
  630.     CALL_(getoffset)
  631.     ld hl,CURSGRAM1
  632.     CALL_(putoff)
  633.     ld hl,CURSGRAM2
  634.     CALL_(putoff)
  635.     JUMP_(checktheloop)
  636. F2press:
  637.     CALL_(getoffset)
  638.     ld hl,CURSGRAM1
  639.     CALL_(putoff)
  640.     ld hl,CURSGRAM2
  641.     CALL_(puton)
  642.     JUMP_(checktheloop)
  643. F3press:
  644.     CALL_(getoffset)
  645.     ld hl,CURSGRAM1
  646.     CALL_(puton)
  647.     ld hl,CURSGRAM2
  648.     CALL_(putoff)
  649.     JUMP_(checktheloop)
  650. F4press:
  651.     CALL_(getoffset)
  652.     ld hl,CURSGRAM1
  653.     CALL_(puton)
  654.     ld hl,CURSGRAM2
  655.     CALL_(puton)
  656.     JUMP_(checktheloop)
  657.  
  658. puton:
  659.     ld a,(BITNUM)
  660.     or (hl)
  661.     ld (hl),a
  662.     ret
  663. putoff:
  664.     ld a,(BITNUM)
  665.     cpl
  666.     and (hl)
  667.     ld (hl),a
  668.     ret
  669.  
  670. putcursor:
  671.     CALL_(getoffset)
  672.     push af
  673.     ld de,(GRAM1)
  674.     add hl,de
  675.     ld a,(hl)
  676.     ld (CURSGRAM1),a
  677.     ld de,$0400
  678.     add hl,de
  679.     ld a,(hl)
  680.     ld (CURSGRAM2),a
  681.     pop af
  682.     push af
  683.     xor (hl)
  684.     ld (hl),a
  685.     or a
  686.     sbc hl,de
  687.     pop af
  688.     xor (hl)
  689.     ld (hl),a
  690.     ret
  691.  
  692. removecursor:
  693.     CALL_(getoffset)
  694.     ld a,(CURSGRAM1)
  695.     ld de,(GRAM1)
  696.     add hl,de
  697.     ld (hl),a
  698.     ld a,(CURSGRAM2)
  699.     ld de,$0400
  700.     add hl,de
  701.     ld (hl),a
  702.     ret
  703.  
  704. boxfill:
  705.     CALL_(removecursor)            ;interrupts still running though
  706.     CALL_(finddepth)        ;normal finddepth
  707.     ld a,(DEPTH)
  708.     ld (BOXDEPTH),a                ;top left corner defines depth
  709.     ld hl,(XCOORD)            ;includes ycoord
  710.     dec h                ;dec ycoord 
  711.     inc l                 ;inc xcoord
  712.     ld (XCOORD),hl            ;new ones
  713.     ld a,h
  714.     ld (BOXTOP),a
  715. linefill:
  716.     CALL_(getoffset)        ;good thing to do first, sets BITNUM and OFFSET
  717.     CALL_(finddepth)
  718.     ld a,(DEPTH)            ;of current pixel
  719.     ld hl,BOXDEPTH
  720.     cp (hl)
  721.     jr z,donelinefill
  722.     ld a,(hl)            ;hl BOXDEPTH
  723.     ld hl,(GRAM2)
  724.     ld de,(OFFSET)
  725.     add hl,de
  726.     rra                ;checks GRAM2 info into carry flag
  727.     push af                ;this is for a
  728.     push af            ;this is for falgs
  729.     CALL_C(puton)
  730.     pop af
  731.     CALL_NC(putoff)
  732.     ld de,$0400
  733.     or a                ;scf  \  ccf
  734.     sbc hl,de
  735.     pop af                ;saved a from one rotation
  736.     rra       ;do again for GRAM1
  737.     push af            ;for flags
  738.     CALL_C(puton)
  739.     pop af
  740.     CALL_NC(putoff)
  741.     ld a,(YCOORD)
  742.     or a                ;checks to see if ycoord at bottom
  743.     jr z,donelinefill
  744.     dec a                    ;dec ycoord for next pixel
  745.     ld (YCOORD),a
  746.     jr linefill
  747. donelinefill:
  748.     ld a,(XCOORD)
  749.     cp $6F
  750.     jr z,doneboxfill
  751.     inc a
  752.     ld (XCOORD),a
  753.     ld a,(BOXTOP)
  754.     ld (YCOORD),a
  755.     CALL_(getoffset)        ;good thing to do first, sets BITNUM and OFFSET
  756.     CALL_(finddepth)
  757.     ld a,(DEPTH)            ;of current pixel
  758.     ld hl,BOXDEPTH
  759.     cp (hl)
  760.     jr z,doneboxfill
  761.     jr linefill
  762. doneboxfill:
  763.     ld a,(BOXTOP)
  764.     inc a
  765.     ld (YCOORD),a
  766.     CALL_(putcursor)
  767.     JUMP_(checktheloop)
  768.  
  769.  
  770. ;+++++++++++++++++++++++++++++++++++++++++++
  771. ;+++++++++++++++++++++++++++++++++++++++++++
  772. ;++This is the start of the viewing screen++
  773. ;+++++++++++++++++++++++++++++++++++++++++++
  774. ;+++++++++++++++++++++++++++++++++++++++++++
  775. viewpicture:
  776.     ld a,(STEREOIND)
  777.     rlca
  778.     rlca
  779.     ld c,a
  780.     ld b,0
  781.     ld hl,(PROGRAM_ADDR)
  782.     ld de,stereodata
  783.     add hl,de
  784.     add hl,bc
  785.     inc hl
  786.     inc hl                ;now it's at address
  787.     call LD_HL_MHL
  788.     push hl            ;\puts in bc
  789.     pop bc            ;/
  790.     ld de,($8BE1)
  791.     or a
  792.     sbc hl,de
  793.     ld a,(MEMFREE)
  794.     ld e,a
  795.     ld d,0
  796.     add hl,de
  797.     ld a,l
  798.     or h
  799.     or a
  800.     JUMP_Z(nomemfornew)
  801.     push bc
  802.     pop hl
  803.     ld (GRAM1),hl
  804.     ld de,$0400
  805.     add hl,de
  806.     ld (GRAM2),hl
  807.  
  808.     ROM_CALL(CLEARLCD)      ;clears
  809.     ld a,$00                ;clears the x coordinates
  810.     ld (BEGXCOORD),a            ;both
  811.     ld (XCOORD),a            ;both
  812.     ld a,$3F                ;this is the y coordinate
  813.     ld (YCOORD),a            ;in correct spot
  814.     ld bc,$0000             ;offset is zero right now
  815.     ld (OFFSET),bc           ;into there
  816.     ld a,$80                ;$80=10000000b, first bit to check depth
  817.     ld (BITNUM),a            ;into theere
  818.     ld a,$00                ;random pointer is zero right now
  819.     ld (RANDNUM),a            ;into there
  820.     CALL_(random)           ;go get the first random number
  821. loopdeloop:
  822.     ld a,(XCOORD)            ;the x coord
  823.     ld b,a                  ;in b
  824.     ld a,(YCOORD)            ;the y coord
  825.     ld c,a                  ;in c
  826.     ROM_CALL(FIND_PIXEL)    ;find correct pixel
  827.     ld d,a                  ;hold in d
  828.     ld bc,$FC00             ;start video mem
  829.     add hl,bc               ;add offset from find pixel
  830.     ld (GRAPHMEM),hl           ;place in video mem to store
  831.     ld a,(RANDBIT)            ;is the random number from last called
  832.     cp 0                    ;if zero
  833.     CALL_Z(makeoffpixel)    ;go to routine to display white pixel
  834.     ld a,(RANDBIT)            ;get again
  835.     cp 0                    ;if not zero
  836.     CALL_NZ(makeonpixel)    ;go to routine to display black pixel
  837.     CALL_(getoffset)
  838.     CALL_(finddepth)        ;find the depth, not needed first time thru
  839.     ld a,(XCOORD)            ;get movable x coord
  840.     ld b,$10                ;add 16(jump 2 bytes, repetition pattern)
  841.     add a,b                 ;right here
  842.     ld (XCOORD),a            ;load it back
  843.     ld a,(DEPTH)            ;the depth
  844.     ld b,a                  ;into b
  845.     ld a,(XCOORD)            ;the x coord in  a
  846.     sub b                 ;subtract so higher depth is moved to left
  847.     ld (XCOORD),a            ;and load back
  848.     ld b,$80                ;$80=10000000
  849.     and b                   ;if b's high bit is set
  850.     cp 0                    ;that would make this not equal
  851.     CALL_NZ(resetbit)       ;so you go here
  852.     ld a,(BEGXCOORD)            ;if the x coord is 16
  853.     cp $10                  ;two bytes and their repeats done with
  854.     CALL_Z(resetline)       ;go to next line
  855.     ld a,(YCOORD)            ;if the y coord has moved from 0 to FF
  856.     cp $FF                  ;checked here
  857.     JUMP_Z(thatsit)         ;stop it cause it's done
  858.     JUMP_(loopdeloop)       ;or continue
  859.  
  860. makeoffpixel:
  861.     ld hl,(GRAPHMEM)           ;place in video mem
  862.     ld a,$FF                ;wish there was a not function
  863.     sbc a,d                 ;for that  ;d is bit from find_pixel
  864.     and (hl)                ;and it
  865.     ld (hl),a               ;load it
  866.     ret                     ;return
  867.  
  868. makeonpixel:
  869.     ld hl,(GRAPHMEM)           ;place in video mem
  870.     ld a,d                  ;put d into a
  871.     or (hl)                 ;or it with hl
  872.     ld (hl),a               ;then load
  873.     ret                     ;return
  874.  
  875. resetbit:
  876.     ld a,(BEGXCOORD)            ;beginning x coord
  877.     inc a                   ;increment it *the bit to test is different
  878.     ld (BEGXCOORD),a            ;load it into *later on in finddepth
  879.     ld (XCOORD),a            ;beginnning and moving x coords
  880.     CALL_(random)           ;get a new random number
  881.     ret                     ;and return
  882.  
  883. resetline:
  884.     ld a,$00                ;\
  885.     ld (BEGXCOORD),a            ; }set x coords completely to 0
  886.     ld (XCOORD),a            ;/
  887.     ld a,(YCOORD)            ;get y 
  888.     dec a                   ;dec to next line
  889.     ld (YCOORD),a            ;and load back
  890.     ret                     ;return
  891.  
  892. thatsit:
  893.     ld hl,$FC00             ;\
  894.     ld de,$8641             ; \moves stereogram in video mem to 
  895.     ld bc,$0400             ; /graphx mem to store
  896.     ldir                    ;/
  897. timetolook:
  898.     call GET_KEY            ;checks keys
  899.     cp K_EXIT
  900.     JUMP_Z(screen)          ;press exit, go to beginning screen
  901.     cp K_PLUS
  902.     JUMP_Z(contrastup)
  903.     cp K_MINUS
  904.     JUMP_Z(contrastdown)
  905.     JUMP_(timetolook)       ;or continues
  906.  
  907. contrastup:
  908.     ld a,($8007)            ;need two different sets of contrast change
  909.     inc a                   ;cause jumps to different place afterwards
  910.     inc a                   ;\/
  911.     ld ($8007),a            ;\/
  912.     out (2),a               ;\/
  913. contrastdown:                   ;\/
  914.     ld a,($8007)            ;\/
  915.     dec a                   ;\/
  916.     ld ($8007),a            ;\/
  917.     out (2),a               ;\/
  918.     JUMP_(timetolook)       ;__
  919.  
  920.  
  921.  
  922. ;+++++++++++++++++++++++++++++++++++++
  923. ;++This is the random number routine++
  924. ;+++++++++++++++++++++++++++++++++++++
  925. random:
  926.     ld hl,(PROGRAM_ADDR)    ;\
  927.     ld de,rnumbers         ; }get address for random numbers 0 to 46
  928.     add hl,de               ;/
  929.     ld a,(RANDNUM)            ;use current random pointer ;starts at 0
  930.     ld c,a                  ;to put
  931.     ld b,0                  ;in bc
  932.     add hl,bc               ;and add up the whole thing
  933.     ld a,(hl)               ;get new pointer pointed to by old pointer
  934.     cp $FF                    ;if gets to be 0 which is final number
  935.     jr z,mixupbytes      ;mix up the bytes
  936.     ld (RANDNUM),a            ;load the new pointer
  937.     and %00000001
  938.     ld (RANDBIT),a            ;is new random number
  939.     ret                     ;return
  940. mixupbytes:
  941.     ld hl,(PROGRAM_ADDR)    ;\
  942.     ld de,rnumbers         ; }get this thing again
  943.     add hl,de               ;/
  944.     ld c,(hl)               ;c holds first one
  945. mixupbytes2:
  946.     inc hl                  ;this routine moves all the bytes 
  947.     ld b,(hl)               ;one byte to the left
  948.     dec hl                  ;I'm not gonna explain it all
  949.     ld (hl),b
  950.     inc hl
  951.     inc hl
  952.     ld a,(hl)
  953.     cp $FF
  954.     jr z,mixupbytes3
  955.     dec hl
  956.     jr mixupbytes2
  957. mixupbytes3:
  958.     dec hl
  959.     ld (hl),c               ;c is put in last spot------------------\
  960.     ld a,0                  ;                                        |
  961.     ld (RANDNUM),a            ;0 is new pointer                        |
  962.     jr random           ;goes back to beginning to rerandom it   |
  963. rnumbers:                                                              ;|
  964.     .db 6,3,9,10,21,15,17,1,18,16,11,13,20,29,23                    ;|
  965.     .db 2,4,5,7,8,12,14,19,22,25,24,27,28,26,30     ;\/-------------/               
  966.     .db 31,33,32,35,45,34,38,36,39,40,41,42,43,44,37,46,$FF
  967.                                    ;took out 25
  968. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  969. ;                      getoffset            +
  970. ;Input:                            +
  971. ;    (XCOORD)=x coordinate                +
  972. ;    (YCOORD)=y coordinate                +
  973. ;Output:                        +
  974. ;    (BITNUM)=bit number of pixel            +    
  975. ;    (OFFSET)=offset of pixel in stereogram1 and 2   +
  976. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  977. getoffset:                      ;kinda like change depth from editing screen
  978.     ld a,(XCOORD)
  979.     ld b,a
  980.     ld a,(YCOORD)
  981.     ld c,a
  982.     ROM_CALL(FIND_PIXEL)
  983.     ld (BITNUM),a
  984.     ld (OFFSET),hl
  985.     ret
  986.  
  987. ;+++++++++++++++++++++++++++++++++++++++++
  988. ;++This is the routine to find the depth++
  989. ;+++++++++++++++++++++++++++++++++++++++++
  990. finddepth:
  991.     CALL_(getoffset)
  992.     ld c,0
  993.     ld hl,(GRAM1)           ;\                  ;  }move stuff, add offset and stereogram1
  994.     ld de,(OFFSET)          ; /
  995.     add hl,de               ;/
  996.     ld a,(BITNUM)            ;bit to test
  997.     and (hl)                ;and to see if bit in mem is set
  998.     ld b,a
  999.     sub a            ;a is zero
  1000.     sub b            ;sub b(zero or nonzer) from 0
  1001.     rl c                ;rotate carry into c
  1002.     ld de,$0400
  1003.     add hl,de            ;get to next stereogram
  1004.     ld a,(BITNUM)
  1005.     and (hl)
  1006.     ld b,a
  1007.     sub a
  1008.     sub b
  1009.     rl c            ;c = %000000(bit from gram 1)(bit from gram 2) = 0,1,2 or 3
  1010.     ld a,c
  1011.     ld (DEPTH),a
  1012.     ret
  1013.  
  1014.                     ;words converted to numbers by compiler
  1015. ;++++++++++++++++++++++++++++++++                    \/
  1016. ;++These are phrases to display++     KEY~~~~~.db "string",$0A,$00
  1017. ;++++++++++++++++++++++++++++++++              /\           /\  /\
  1018. title:                      ;tells compiler string of numbers|   |
  1019.     .db "Viewer",0                      ;                |  00 terminate
  1020. stuff:                                         ;       immediate number 
  1021.     .db "Stereogram:",0
  1022. version:                                   
  1023.     .db "v1.5-(6/25/97)",0
  1024. myname:
  1025.     .db "By: ",$0A,"lan ",$0B,"ailey",0
  1026. myemail:
  1027.     .db "<bailala@mw.sisna.com>",0
  1028. choices:
  1029.     .db "F1-Edit   F2-View   F3-Quit",0
  1030. displaystuff:
  1031.     .db "x=",0
  1032.     .db "y=",0
  1033.  
  1034.  
  1035.     .db 'w','e','N'
  1036. newstereo:
  1037.     .db $03
  1038.  
  1039. nomemstring:
  1040.     .db "Get More Mem!",0
  1041.  
  1042. ;++++++++++++++++++++++++++
  1043. ;++Stores different stuff++
  1044. ;++++++++++++++++++++++++++
  1045. numberstring:
  1046.     .db $00,$00,$00
  1047.  
  1048. introut:
  1049.     ex af,af'
  1050.     exx
  1051.     ld a,(WHICHGRAM)
  1052.     or a                    ;cp 0
  1053.     jr z,disp2
  1054.     rra                ;makes 2->1, 1->0
  1055.     ld (WHICHGRAM),a
  1056.     ld hl,(GRAM1)
  1057.     ld de,$FC00
  1058.     ld bc,$0400
  1059.     ldir
  1060.     jr introut2
  1061. disp2:
  1062.     set 1,a                    ;a was zero, so now 2
  1063.     ld (WHICHGRAM),a
  1064.     ld hl,(GRAM2)
  1065.     ld de,$FC00
  1066.     ld bc,$0400
  1067.     ldir
  1068.     nop                ;a little timing fix
  1069. introut2:
  1070.     ld a,(COUNTER)
  1071.     ld b,a
  1072. introutloop:
  1073.     nop
  1074.     nop
  1075.     nop
  1076.     djnz introutloop
  1077.     exx
  1078.     ex af,af'
  1079.     jp $38
  1080. introutend:
  1081.  
  1082. graphic:
  1083.     .db %00001111,%11000000,%01111100,%00000000
  1084.     .db %00000001,%11110000,%00111111,%00000000
  1085.     .db %00000000,%01111000,%00110011,%10000000
  1086.     .db %00000000,%00111000,%00111001,%11000000
  1087.     .db %00000000,%01111000,%00111000,%11000000
  1088.     .db %00000001,%11110011,%00111000,%11000000
  1089.     .db %00000111,%11000011,%10111000,%11000000
  1090.     .db %00000001,%11110011,%00111000,%11000000
  1091.     .db %00000000,%01111000,%00111000,%11000000
  1092.     .db %00000000,%00111000,%00111001,%11000000
  1093.     .db %00000000,%01111000,%00110011,%10000000
  1094.     .db %00000001,%11110000,%00111111,%00000000
  1095.     .db %00001111,%11000000,%01111100,%00000000
  1096.  
  1097. stereodata:
  1098.     .dw $0000,$0000
  1099.     .dw $0000,$0000
  1100.     .dw $0000,$0000
  1101.     .dw $0000,$0000
  1102.     .dw $0000,$0000
  1103.     .dw $0000,$0000
  1104.     .dw $0000,$0000
  1105.     .dw $0000,$0000
  1106.     .dw $0000,$0000
  1107.     .dw $0000,$0000
  1108.     .dw $0000,$0000
  1109.     .dw $0000,$0000
  1110.     .dw $0000,$0000
  1111.  
  1112.  
  1113.  
  1114. .end
  1115.  
  1116. ;Comments prevent TASM to say "No END directive before EOF"
  1117.