ManuFlosoYT

Cube.s

Feb 18th, 2026
129
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.22 KB | Source Code | 0 0
  1. ;
  2. ; File generated by cc65 v 2.18 - Fedora 2.19-13.fc43
  3. ;
  4. .fopt compiler,"cc65 v 2.18 - Fedora 2.19-13.fc43"
  5. .setcpu "65C02"
  6. .smart on
  7. .autoimport on
  8. .case on
  9. .debuginfo off
  10. .importzp sp, sreg, regsave, regbank
  11. .importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
  12. .macpack longbranch
  13. .forceimport __STARTUP__
  14. .import _rand
  15. .import _srand
  16. .import _MONRDKEY
  17. .import _MONCOUT
  18. .import _MONGETCHAR_NB
  19. .import _INIT_BUFFER
  20. .export _print_str
  21. .export _read_line
  22. .export _print_hex_byte
  23. .export _print_hex
  24. .export _print_num
  25. .export _delay
  26. .import _memset
  27. .export _gpu_put_pixel
  28. .export _gpu_draw_rect
  29. .export _gpu_fill_screen
  30. .export _gpu_abs
  31. .export _gpu_swap_coord
  32. .export _gpu_draw_line
  33. .export _gpu_draw_tri
  34. .export _GPUdelay
  35. .export _gpu_test_pattern
  36. .export _lcd_send_nibble
  37. .export _lcd_instruction
  38. .export _lcd_print_char
  39. .export _lcd_clear
  40. .export _lcd_newline
  41. .export _lcd_init
  42. .export _lcd_print
  43. .export _lcd_print_number
  44. .export _SIN_TABLE
  45. .export _via_init
  46. .export _vx
  47. .export _vy
  48. .export _vz
  49. .export _px
  50. .export _py
  51. .export _cvx
  52. .export _cvy
  53. .export _cvz
  54. .export _faces
  55. .export _face_colors
  56. .export _visible_faces
  57. .export _rotate_all
  58. .export _project_all
  59. .export _init_graphics
  60. .export _black_color
  61. .export _main
  62.  
  63. .segment "RODATA"
  64.  
  65. _SIN_TABLE:
  66. .byte $00
  67. .byte $02
  68. .byte $05
  69. .byte $08
  70. .byte $0A
  71. .byte $0D
  72. .byte $10
  73. .byte $12
  74. .byte $15
  75. .byte $18
  76. .byte $1A
  77. .byte $1D
  78. .byte $1F
  79. .byte $22
  80. .byte $25
  81. .byte $27
  82. .byte $2A
  83. .byte $2C
  84. .byte $2F
  85. .byte $31
  86. .byte $33
  87. .byte $36
  88. .byte $38
  89. .byte $3A
  90. .byte $3D
  91. .byte $3F
  92. .byte $41
  93. .byte $43
  94. .byte $45
  95. .byte $47
  96. .byte $49
  97. .byte $4B
  98. .byte $4D
  99. .byte $4F
  100. .byte $51
  101. .byte $53
  102. .byte $55
  103. .byte $56
  104. .byte $58
  105. .byte $59
  106. .byte $5B
  107. .byte $5C
  108. .byte $5E
  109. .byte $5F
  110. .byte $61
  111. .byte $62
  112. .byte $63
  113. .byte $64
  114. .byte $65
  115. .byte $66
  116. .byte $67
  117. .byte $68
  118. .byte $69
  119. .byte $6A
  120. .byte $6A
  121. .byte $6B
  122. .byte $6B
  123. .byte $6C
  124. .byte $6C
  125. .byte $6D
  126. .byte $6D
  127. .byte $6D
  128. .byte $6D
  129. .byte $6D
  130. .byte $6E
  131. .byte $6D
  132. .byte $6D
  133. .byte $6D
  134. .byte $6D
  135. .byte $6D
  136. .byte $6C
  137. .byte $6C
  138. .byte $6B
  139. .byte $6B
  140. .byte $6A
  141. .byte $6A
  142. .byte $69
  143. .byte $68
  144. .byte $67
  145. .byte $66
  146. .byte $65
  147. .byte $64
  148. .byte $63
  149. .byte $62
  150. .byte $61
  151. .byte $5F
  152. .byte $5E
  153. .byte $5C
  154. .byte $5B
  155. .byte $59
  156. .byte $58
  157. .byte $56
  158. .byte $55
  159. .byte $53
  160. .byte $51
  161. .byte $4F
  162. .byte $4D
  163. .byte $4B
  164. .byte $49
  165. .byte $47
  166. .byte $45
  167. .byte $43
  168. .byte $41
  169. .byte $3F
  170. .byte $3D
  171. .byte $3A
  172. .byte $38
  173. .byte $36
  174. .byte $33
  175. .byte $31
  176. .byte $2F
  177. .byte $2C
  178. .byte $2A
  179. .byte $27
  180. .byte $25
  181. .byte $22
  182. .byte $1F
  183. .byte $1D
  184. .byte $1A
  185. .byte $18
  186. .byte $15
  187. .byte $12
  188. .byte $10
  189. .byte $0D
  190. .byte $0A
  191. .byte $08
  192. .byte $05
  193. .byte $02
  194. .byte $00
  195. .byte $FE
  196. .byte $FB
  197. .byte $F8
  198. .byte $F6
  199. .byte $F3
  200. .byte $F0
  201. .byte $EE
  202. .byte $EB
  203. .byte $E8
  204. .byte $E6
  205. .byte $E3
  206. .byte $E1
  207. .byte $DE
  208. .byte $DB
  209. .byte $D9
  210. .byte $D6
  211. .byte $D4
  212. .byte $D1
  213. .byte $CF
  214. .byte $CD
  215. .byte $CA
  216. .byte $C8
  217. .byte $C6
  218. .byte $C3
  219. .byte $C1
  220. .byte $BF
  221. .byte $BD
  222. .byte $BB
  223. .byte $B9
  224. .byte $B7
  225. .byte $B5
  226. .byte $B3
  227. .byte $B1
  228. .byte $AF
  229. .byte $AD
  230. .byte $AB
  231. .byte $AA
  232. .byte $A8
  233. .byte $A7
  234. .byte $A5
  235. .byte $A4
  236. .byte $A2
  237. .byte $A1
  238. .byte $9F
  239. .byte $9E
  240. .byte $9D
  241. .byte $9C
  242. .byte $9B
  243. .byte $9A
  244. .byte $99
  245. .byte $98
  246. .byte $97
  247. .byte $96
  248. .byte $96
  249. .byte $95
  250. .byte $95
  251. .byte $94
  252. .byte $94
  253. .byte $93
  254. .byte $93
  255. .byte $93
  256. .byte $93
  257. .byte $93
  258. .byte $92
  259. .byte $93
  260. .byte $93
  261. .byte $93
  262. .byte $93
  263. .byte $93
  264. .byte $94
  265. .byte $94
  266. .byte $95
  267. .byte $95
  268. .byte $96
  269. .byte $96
  270. .byte $97
  271. .byte $98
  272. .byte $99
  273. .byte $9A
  274. .byte $9B
  275. .byte $9C
  276. .byte $9D
  277. .byte $9E
  278. .byte $9F
  279. .byte $A1
  280. .byte $A2
  281. .byte $A4
  282. .byte $A5
  283. .byte $A7
  284. .byte $A8
  285. .byte $AA
  286. .byte $AB
  287. .byte $AD
  288. .byte $AF
  289. .byte $B1
  290. .byte $B3
  291. .byte $B5
  292. .byte $B7
  293. .byte $B9
  294. .byte $BB
  295. .byte $BD
  296. .byte $BF
  297. .byte $C1
  298. .byte $C3
  299. .byte $C6
  300. .byte $C8
  301. .byte $CA
  302. .byte $CD
  303. .byte $CF
  304. .byte $D1
  305. .byte $D4
  306. .byte $D6
  307. .byte $D9
  308. .byte $DB
  309. .byte $DE
  310. .byte $E1
  311. .byte $E3
  312. .byte $E6
  313. .byte $E8
  314. .byte $EB
  315. .byte $EE
  316. .byte $F0
  317. .byte $F3
  318. .byte $F6
  319. .byte $F8
  320. .byte $FB
  321. .byte $FE
  322. _cvx:
  323. .byte $EA
  324. .byte $16
  325. .byte $16
  326. .byte $EA
  327. .byte $EA
  328. .byte $16
  329. .byte $16
  330. .byte $EA
  331. _cvy:
  332. .byte $EA
  333. .byte $EA
  334. .byte $16
  335. .byte $16
  336. .byte $EA
  337. .byte $EA
  338. .byte $16
  339. .byte $16
  340. _cvz:
  341. .byte $EA
  342. .byte $EA
  343. .byte $EA
  344. .byte $EA
  345. .byte $16
  346. .byte $16
  347. .byte $16
  348. .byte $16
  349. _faces:
  350. .byte $04
  351. .byte $05
  352. .byte $06
  353. .byte $04
  354. .byte $06
  355. .byte $07
  356. .byte $01
  357. .byte $00
  358. .byte $03
  359. .byte $01
  360. .byte $03
  361. .byte $02
  362. .byte $05
  363. .byte $01
  364. .byte $02
  365. .byte $05
  366. .byte $02
  367. .byte $06
  368. .byte $00
  369. .byte $04
  370. .byte $07
  371. .byte $00
  372. .byte $07
  373. .byte $03
  374. .byte $07
  375. .byte $06
  376. .byte $02
  377. .byte $07
  378. .byte $02
  379. .byte $03
  380. .byte $00
  381. .byte $01
  382. .byte $05
  383. .byte $00
  384. .byte $05
  385. .byte $04
  386. _face_colors:
  387. .byte $E0
  388. .byte $E0
  389. .byte $03
  390. .byte $03
  391. .byte $E3
  392. .byte $E3
  393. .byte $1C
  394. .byte $1C
  395. .byte $FC
  396. .byte $FC
  397. .byte $93
  398. .byte $93
  399. _black_color:
  400. .byte $00
  401. L0584:
  402. .byte $50,$52,$45,$53,$53,$20,$41,$4E,$59,$20,$4B,$45,$59,$20,$54,$4F
  403. .byte $20,$47,$45,$4E,$45,$52,$41,$54,$45,$20,$53,$45,$45,$44,$3A,$20
  404. .byte $00
  405. L0591:
  406. .byte $52,$6F,$74,$61,$74,$69,$6E,$67,$20,$43,$75,$62,$65,$00
  407.  
  408. .segment "BSS"
  409.  
  410. _vx:
  411. .res 8,$00
  412. _vy:
  413. .res 8,$00
  414. _vz:
  415. .res 8,$00
  416. _px:
  417. .res 8,$00
  418. _py:
  419. .res 8,$00
  420. _visible_faces:
  421. .res 36,$00
  422.  
  423. ; ---------------------------------------------------------------
  424. ; void __near__ print_str (__near__ const unsigned char *)
  425. ; ---------------------------------------------------------------
  426.  
  427. .segment "CODE"
  428.  
  429. .proc _print_str: near
  430.  
  431. .segment "CODE"
  432.  
  433. ;
  434. ; void print_str(const char* s) {
  435. ;
  436. jsr pushax
  437. ;
  438. ; while (*s) {
  439. ;
  440. bra L0004
  441. ;
  442. ; if (*s == '\n') {
  443. ;
  444. L0002: ldy #$01
  445. lda (sp),y
  446. sta ptr1+1
  447. lda (sp)
  448. sta ptr1
  449. lda (ptr1)
  450. cmp #$0A
  451. bne L0006
  452. ;
  453. ; bios_putchar('\r');
  454. ;
  455. lda #$0D
  456. jsr _MONCOUT
  457. ;
  458. ; bios_putchar('\n');
  459. ;
  460. lda #$0A
  461. ;
  462. ; } else {
  463. ;
  464. bra L06C1
  465. ;
  466. ; bios_putchar(*s);
  467. ;
  468. L0006: ldy #$01
  469. lda (sp),y
  470. sta ptr1+1
  471. lda (sp)
  472. sta ptr1
  473. lda (ptr1)
  474. L06C1: jsr _MONCOUT
  475. ;
  476. ; s++;
  477. ;
  478. ldy #$01
  479. lda (sp),y
  480. tax
  481. lda (sp)
  482. ina
  483. bne L0010
  484. inx
  485. L0010: jsr stax0sp
  486. ;
  487. ; while (*s) {
  488. ;
  489. L0004: ldy #$01
  490. lda (sp),y
  491. sta ptr1+1
  492. lda (sp)
  493. sta ptr1
  494. lda (ptr1)
  495. bne L0002
  496. ;
  497. ; }
  498. ;
  499. jmp incsp2
  500.  
  501. .endproc
  502.  
  503. ; ---------------------------------------------------------------
  504. ; void __near__ read_line (__near__ unsigned char *, int)
  505. ; ---------------------------------------------------------------
  506.  
  507. .segment "CODE"
  508.  
  509. .proc _read_line: near
  510.  
  511. .segment "BSS"
  512.  
  513. L0012:
  514. .res 1,$00
  515. L0013:
  516. .res 2,$00
  517.  
  518. .segment "CODE"
  519.  
  520. ;
  521. ; void read_line(char* buffer, int max_len) {
  522. ;
  523. jsr pushax
  524. ;
  525. ; int i = 0;
  526. ;
  527. stz L0013
  528. stz L0013+1
  529. ;
  530. ; while (i < max_len - 1) {
  531. ;
  532. bra L0017
  533. ;
  534. ; c = bios_getchar();
  535. ;
  536. L0015: jsr _MONRDKEY
  537. sta L0012
  538. ;
  539. ; } while (c == 0);
  540. ;
  541. lda L0012
  542. beq L0015
  543. ;
  544. ; if (c == '\r' || c == '\n') {
  545. ;
  546. cmp #$0D
  547. beq L06C3
  548. cmp #$0A
  549. bne L0020
  550. ;
  551. ; bios_putchar('\r');
  552. ;
  553. lda #$0D
  554. L06C3: jsr _MONCOUT
  555. ;
  556. ; bios_putchar('\n');
  557. ;
  558. lda #$0A
  559. jsr _MONCOUT
  560. ;
  561. ; break; // Exit loop if Enter is pressed
  562. ;
  563. bra L0016
  564. ;
  565. ; buffer[i] = c;
  566. ;
  567. L0020: ldy #$03
  568. lda (sp),y
  569. tax
  570. dey
  571. lda (sp),y
  572. clc
  573. adc L0013
  574. sta ptr1
  575. txa
  576. adc L0013+1
  577. sta ptr1+1
  578. lda L0012
  579. sta (ptr1)
  580. ;
  581. ; i++;
  582. ;
  583. lda L0013
  584. ldx L0013+1
  585. ina
  586. bne L002B
  587. inx
  588. L002B: sta L0013
  589. stx L0013+1
  590. ;
  591. ; while (i < max_len - 1) {
  592. ;
  593. L0017: lda L0013
  594. ldx L0013+1
  595. jsr pushax
  596. ldy #$03
  597. lda (sp),y
  598. tax
  599. dey
  600. lda (sp),y
  601. sec
  602. sbc #$01
  603. bcs L0019
  604. dex
  605. L0019: jsr tosicmp
  606. bmi L0015
  607. ;
  608. ; buffer[i] = '\0';
  609. ;
  610. L0016: ldy #$03
  611. lda (sp),y
  612. tax
  613. dey
  614. lda (sp),y
  615. clc
  616. adc L0013
  617. sta ptr1
  618. txa
  619. adc L0013+1
  620. sta ptr1+1
  621. lda #$00
  622. sta (ptr1)
  623. ;
  624. ; }
  625. ;
  626. jmp incsp4
  627.  
  628. .endproc
  629.  
  630. ; ---------------------------------------------------------------
  631. ; void __near__ print_hex_byte (unsigned char)
  632. ; ---------------------------------------------------------------
  633.  
  634. .segment "CODE"
  635.  
  636. .proc _print_hex_byte: near
  637.  
  638. .segment "RODATA"
  639.  
  640. L0032:
  641. .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$41,$42,$43,$44,$45,$46
  642. .byte $00
  643.  
  644. .segment "BSS"
  645.  
  646. L0031:
  647. .res 17,$00
  648.  
  649. .segment "CODE"
  650.  
  651. ;
  652. ; void print_hex_byte(unsigned char v) {
  653. ;
  654. jsr pusha
  655. ;
  656. ; const char hex[] = "0123456789ABCDEF";
  657. ;
  658. ldy #$10
  659. L0033: lda L0032,y
  660. sta L0031,y
  661. dey
  662. bpl L0033
  663. ;
  664. ; bios_putchar(hex[(v >> 4) & 0xF]);
  665. ;
  666. lda (sp)
  667. lsr a
  668. lsr a
  669. lsr a
  670. lsr a
  671. and #$0F
  672. sta ptr1
  673. lda #$00
  674. clc
  675. adc #>(L0031)
  676. sta ptr1+1
  677. ldy #<(L0031)
  678. lda (ptr1),y
  679. jsr _MONCOUT
  680. ;
  681. ; bios_putchar(hex[v & 0xF]);
  682. ;
  683. lda (sp)
  684. and #$0F
  685. sta ptr1
  686. lda #$00
  687. clc
  688. adc #>(L0031)
  689. sta ptr1+1
  690. ldy #<(L0031)
  691. lda (ptr1),y
  692. jsr _MONCOUT
  693. ;
  694. ; }
  695. ;
  696. jmp incsp1
  697.  
  698. .endproc
  699.  
  700. ; ---------------------------------------------------------------
  701. ; void __near__ print_hex (unsigned int)
  702. ; ---------------------------------------------------------------
  703.  
  704. .segment "CODE"
  705.  
  706. .proc _print_hex: near
  707.  
  708. .segment "RODATA"
  709.  
  710. L003E:
  711. .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$41,$42,$43,$44,$45,$46
  712. .byte $00
  713.  
  714. .segment "BSS"
  715.  
  716. L003D:
  717. .res 17,$00
  718.  
  719. .segment "CODE"
  720.  
  721. ;
  722. ; void print_hex(unsigned int n) {
  723. ;
  724. jsr pushax
  725. ;
  726. ; const char hex_chars[] = "0123456789ABCDEF";
  727. ;
  728. ldy #$10
  729. L003F: lda L003E,y
  730. sta L003D,y
  731. dey
  732. bpl L003F
  733. ;
  734. ; bios_putchar('0');
  735. ;
  736. lda #$30
  737. jsr _MONCOUT
  738. ;
  739. ; bios_putchar('x');
  740. ;
  741. lda #$78
  742. jsr _MONCOUT
  743. ;
  744. ; if (n > 255) {
  745. ;
  746. ldy #$01
  747. lda (sp),y
  748. tax
  749. lda (sp)
  750. cmp #$00
  751. txa
  752. sbc #$01
  753. bcc L0044
  754. ;
  755. ; bios_putchar(hex_chars[(n >> 12) & 0xF]);
  756. ;
  757. ldy #$01
  758. lda (sp),y
  759. lsr a
  760. lsr a
  761. lsr a
  762. lsr a
  763. and #$0F
  764. sta ptr1
  765. lda #$00
  766. clc
  767. adc #>(L003D)
  768. sta ptr1+1
  769. ldy #<(L003D)
  770. lda (ptr1),y
  771. jsr _MONCOUT
  772. ;
  773. ; bios_putchar(hex_chars[(n >> 8) & 0xF]);
  774. ;
  775. ldy #$01
  776. lda (sp),y
  777. and #$0F
  778. sta ptr1
  779. lda #$00
  780. clc
  781. adc #>(L003D)
  782. sta ptr1+1
  783. ldy #<(L003D)
  784. lda (ptr1),y
  785. jsr _MONCOUT
  786. ;
  787. ; bios_putchar(hex_chars[(n >> 4) & 0xF]);
  788. ;
  789. L0044: ldy #$01
  790. lda (sp),y
  791. tax
  792. lda (sp)
  793. jsr shrax4
  794. and #$0F
  795. sta ptr1
  796. lda #$00
  797. clc
  798. adc #>(L003D)
  799. sta ptr1+1
  800. ldy #<(L003D)
  801. lda (ptr1),y
  802. jsr _MONCOUT
  803. ;
  804. ; bios_putchar(hex_chars[n & 0xF]);
  805. ;
  806. lda (sp)
  807. and #$0F
  808. sta ptr1
  809. lda #$00
  810. clc
  811. adc #>(L003D)
  812. sta ptr1+1
  813. ldy #<(L003D)
  814. lda (ptr1),y
  815. jsr _MONCOUT
  816. ;
  817. ; }
  818. ;
  819. jmp incsp2
  820.  
  821. .endproc
  822.  
  823. ; ---------------------------------------------------------------
  824. ; void __near__ print_num (unsigned int)
  825. ; ---------------------------------------------------------------
  826.  
  827. .segment "CODE"
  828.  
  829. .proc _print_num: near
  830.  
  831. .segment "BSS"
  832.  
  833. L0057:
  834. .res 10,$00
  835. L0058:
  836. .res 2,$00
  837.  
  838. .segment "CODE"
  839.  
  840. ;
  841. ; void print_num(unsigned int n) {
  842. ;
  843. jsr pushax
  844. ;
  845. ; int idx = 0;
  846. ;
  847. stz L0058
  848. stz L0058+1
  849. ;
  850. ; if (n == 0) {
  851. ;
  852. lda (sp)
  853. ldy #$01
  854. ora (sp),y
  855. bne L0061
  856. ;
  857. ; bios_putchar('0');
  858. ;
  859. lda #$30
  860. jsr _MONCOUT
  861. ;
  862. ; return;
  863. ;
  864. jmp incsp2
  865. ;
  866. ; buffer[idx++] = (n % 10) + '0';
  867. ;
  868. L005F: lda L0058
  869. ldx L0058+1
  870. sta regsave
  871. stx regsave+1
  872. ina
  873. bne L0066
  874. inx
  875. L0066: sta L0058
  876. stx L0058+1
  877. lda regsave
  878. clc
  879. adc #<(L0057)
  880. tay
  881. lda regsave+1
  882. adc #>(L0057)
  883. tax
  884. tya
  885. jsr pushax
  886. ldy #$05
  887. jsr pushwysp
  888. lda #$0A
  889. jsr tosumoda0
  890. clc
  891. adc #$30
  892. ldy #$00
  893. jsr staspidx
  894. ;
  895. ; n /= 10;
  896. ;
  897. jsr pushw0sp
  898. lda #$0A
  899. jsr tosudiva0
  900. jsr stax0sp
  901. ;
  902. ; while (n > 0) {
  903. ;
  904. L0061: lda (sp)
  905. ldy #$01
  906. ora (sp),y
  907. bne L005F
  908. ;
  909. ; while (idx > 0) {
  910. ;
  911. bra L006E
  912. ;
  913. ; bios_putchar(buffer[--idx]);
  914. ;
  915. L006C: lda L0058
  916. sec
  917. sbc #$01
  918. sta L0058
  919. bcs L0074
  920. dec L0058+1
  921. L0074: sta ptr1
  922. lda L0058+1
  923. clc
  924. adc #>(L0057)
  925. sta ptr1+1
  926. ldy #<(L0057)
  927. lda (ptr1),y
  928. jsr _MONCOUT
  929. ;
  930. ; while (idx > 0) {
  931. ;
  932. L006E: lda L0058
  933. cmp #$01
  934. lda L0058+1
  935. sbc #$00
  936. bvs L0070
  937. eor #$80
  938. L0070: bmi L006C
  939. ;
  940. ; }
  941. ;
  942. jmp incsp2
  943.  
  944. .endproc
  945.  
  946. ; ---------------------------------------------------------------
  947. ; void __near__ delay (unsigned int)
  948. ; ---------------------------------------------------------------
  949.  
  950. .segment "CODE"
  951.  
  952. .proc _delay: near
  953.  
  954. .segment "BSS"
  955.  
  956. L0076:
  957. .res 2,$00
  958. L0077:
  959. .res 2,$00
  960.  
  961. .segment "CODE"
  962.  
  963. ;
  964. ; void delay(unsigned int ms) {
  965. ;
  966. jsr pushax
  967. ;
  968. ; for (i = 0; i < ms; i++) {
  969. ;
  970. stz L0076
  971. stz L0076+1
  972. L0078: lda L0076
  973. cmp (sp)
  974. lda L0076+1
  975. ldy #$01
  976. sbc (sp),y
  977. bcs L0079
  978. ;
  979. ; for (j = 0; j < ITERATIONS_PER_MS; j++) {
  980. ;
  981. stz L0077
  982. stz L0077+1
  983. L0081: lda L0077+1
  984. cmp #$0F
  985. bne L0088
  986. lda L0077
  987. cmp #$A0
  988. L0088: bcs L007A
  989. lda L0077
  990. ldx L0077+1
  991. ina
  992. bne L008A
  993. inx
  994. L008A: sta L0077
  995. stx L0077+1
  996. bra L0081
  997. ;
  998. ; for (i = 0; i < ms; i++) {
  999. ;
  1000. L007A: lda L0076
  1001. ldx L0076+1
  1002. ina
  1003. bne L0080
  1004. inx
  1005. L0080: sta L0076
  1006. stx L0076+1
  1007. bra L0078
  1008. ;
  1009. ; }
  1010. ;
  1011. L0079: jmp incsp2
  1012.  
  1013. .endproc
  1014.  
  1015. ; ---------------------------------------------------------------
  1016. ; void __near__ gpu_put_pixel (signed char, signed char, unsigned char)
  1017. ; ---------------------------------------------------------------
  1018.  
  1019. .segment "CODE"
  1020.  
  1021. .proc _gpu_put_pixel: near
  1022.  
  1023. .segment "BSS"
  1024.  
  1025. L008C:
  1026. .res 2,$00
  1027. L008D:
  1028. .res 2,$00
  1029.  
  1030. .segment "CODE"
  1031.  
  1032. ;
  1033. ; void gpu_put_pixel(signed char x, signed char y, unsigned char color) {
  1034. ;
  1035. jsr pusha
  1036. ;
  1037. ; if (x < 0 || x >= GPU_WIDTH || y < 0 || y >= GPU_HEIGHT) {
  1038. ;
  1039. ldy #$02
  1040. lda (sp),y
  1041. asl a
  1042. bcs L008B
  1043. lda (sp),y
  1044. sec
  1045. sbc #$64
  1046. bvs L0092
  1047. eor #$80
  1048. L0092: bmi L008B
  1049. dey
  1050. lda (sp),y
  1051. asl a
  1052. bcs L008B
  1053. lda (sp),y
  1054. sec
  1055. sbc #$40
  1056. bvs L0095
  1057. eor #$80
  1058. L0095: bmi L008B
  1059. ldx #$00
  1060. ;
  1061. ; offset = ((unsigned short)y << 7) + (unsigned char)x;
  1062. ;
  1063. lda (sp),y
  1064. cmp #$80
  1065. bcc L009B
  1066. dex
  1067. L009B: jsr shlax4
  1068. jsr shlax3
  1069. sta ptr1
  1070. stx ptr1+1
  1071. iny
  1072. lda (sp),y
  1073. clc
  1074. adc ptr1
  1075. ldx ptr1+1
  1076. bcc L06C4
  1077. inx
  1078. L06C4: sta L008C
  1079. stx L008C+1
  1080. ;
  1081. ; vram = (unsigned char*)(unsigned long)GPU_VRAM_START;
  1082. ;
  1083. ldx #$20
  1084. lda #$00
  1085. stz L008D
  1086. stx L008D+1
  1087. ;
  1088. ; vram[offset] = color;
  1089. ;
  1090. clc
  1091. adc L008C
  1092. sta ptr1
  1093. txa
  1094. adc L008C+1
  1095. sta ptr1+1
  1096. lda (sp)
  1097. sta (ptr1)
  1098. ;
  1099. ; }
  1100. ;
  1101. L008B: jmp incsp3
  1102.  
  1103. .endproc
  1104.  
  1105. ; ---------------------------------------------------------------
  1106. ; void __near__ gpu_draw_rect (signed char, signed char, signed char, signed char, unsigned char)
  1107. ; ---------------------------------------------------------------
  1108.  
  1109. .segment "CODE"
  1110.  
  1111. .proc _gpu_draw_rect: near
  1112.  
  1113. .segment "BSS"
  1114.  
  1115. L00A2:
  1116. .res 1,$00
  1117. L00A3:
  1118. .res 1,$00
  1119. L00A4:
  1120. .res 1,$00
  1121. L00A5:
  1122. .res 1,$00
  1123. L00A6:
  1124. .res 2,$00
  1125.  
  1126. .segment "CODE"
  1127.  
  1128. ;
  1129. ; unsigned char color) {
  1130. ;
  1131. jsr pusha
  1132. ;
  1133. ; if (x >= GPU_WIDTH || y >= GPU_HEIGHT) return;
  1134. ;
  1135. ldy #$04
  1136. lda (sp),y
  1137. sec
  1138. sbc #$64
  1139. bvs L00AA
  1140. eor #$80
  1141. L00AA: bpl L06D2
  1142. ;
  1143. ; }
  1144. ;
  1145. jmp incsp5
  1146. ;
  1147. ; if (x >= GPU_WIDTH || y >= GPU_HEIGHT) return;
  1148. ;
  1149. L06D2: dey
  1150. lda (sp),y
  1151. sec
  1152. sbc #$40
  1153. bvs L00AC
  1154. eor #$80
  1155. L00AC: bpl L06D3
  1156. ;
  1157. ; }
  1158. ;
  1159. jmp incsp5
  1160. ;
  1161. ; if (x + w < 0 || y + h < 0) return;
  1162. ;
  1163. L06D3: iny
  1164. ldx #$00
  1165. lda (sp),y
  1166. bpl L00B0
  1167. dex
  1168. L00B0: sta ptr1
  1169. stx ptr1+1
  1170. ldx #$00
  1171. ldy #$02
  1172. lda (sp),y
  1173. bpl L00B1
  1174. dex
  1175. L00B1: clc
  1176. adc ptr1
  1177. txa
  1178. adc ptr1+1
  1179. tax
  1180. cpx #$80
  1181. bcc L06D4
  1182. ;
  1183. ; }
  1184. ;
  1185. jmp incsp5
  1186. ;
  1187. ; if (x + w < 0 || y + h < 0) return;
  1188. ;
  1189. L06D4: iny
  1190. ldx #$00
  1191. lda (sp),y
  1192. bpl L00B2
  1193. dex
  1194. L00B2: sta ptr1
  1195. stx ptr1+1
  1196. ldx #$00
  1197. ldy #$01
  1198. lda (sp),y
  1199. bpl L00B3
  1200. dex
  1201. L00B3: clc
  1202. adc ptr1
  1203. txa
  1204. adc ptr1+1
  1205. tax
  1206. cpx #$80
  1207. bcc L06D5
  1208. ;
  1209. ; }
  1210. ;
  1211. jmp incsp5
  1212. ;
  1213. ; if (x < 0) {
  1214. ;
  1215. L06D5: ldy #$04
  1216. lda (sp),y
  1217. asl a
  1218. bcc L00B5
  1219. ;
  1220. ; w += x;
  1221. ;
  1222. lda (sp),y
  1223. cmp #$80
  1224. ldy #$02
  1225. clc
  1226. adc (sp),y
  1227. sta (sp),y
  1228. ;
  1229. ; x = 0;
  1230. ;
  1231. lda #$00
  1232. ldy #$04
  1233. sta (sp),y
  1234. ;
  1235. ; if (y < 0) {
  1236. ;
  1237. L00B5: dey
  1238. lda (sp),y
  1239. asl a
  1240. bcc L00BF
  1241. ;
  1242. ; h += y;
  1243. ;
  1244. lda (sp),y
  1245. cmp #$80
  1246. ldy #$01
  1247. clc
  1248. adc (sp),y
  1249. sta (sp),y
  1250. ;
  1251. ; y = 0;
  1252. ;
  1253. lda #$00
  1254. ldy #$03
  1255. sta (sp),y
  1256. ;
  1257. ; max_x = x + w;
  1258. ;
  1259. L00BF: iny
  1260. ldx #$00
  1261. lda (sp),y
  1262. bpl L00CB
  1263. dex
  1264. L00CB: sta ptr1
  1265. stx ptr1+1
  1266. ldx #$00
  1267. ldy #$02
  1268. lda (sp),y
  1269. bpl L00CC
  1270. dex
  1271. L00CC: clc
  1272. adc ptr1
  1273. pha
  1274. txa
  1275. adc ptr1+1
  1276. pla
  1277. cmp #$80
  1278. sta L00A3
  1279. ;
  1280. ; max_y = y + h;
  1281. ;
  1282. iny
  1283. ldx #$00
  1284. lda (sp),y
  1285. bpl L00D0
  1286. dex
  1287. L00D0: sta ptr1
  1288. stx ptr1+1
  1289. ldx #$00
  1290. ldy #$01
  1291. lda (sp),y
  1292. bpl L00D1
  1293. dex
  1294. L00D1: clc
  1295. adc ptr1
  1296. pha
  1297. txa
  1298. adc ptr1+1
  1299. pla
  1300. cmp #$80
  1301. sta L00A4
  1302. ;
  1303. ; if (max_x > GPU_WIDTH) max_x = GPU_WIDTH;
  1304. ;
  1305. lda L00A3
  1306. sec
  1307. sbc #$65
  1308. bvs L00D6
  1309. eor #$80
  1310. L00D6: bpl L06CF
  1311. lda #$64
  1312. sta L00A3
  1313. ;
  1314. ; if (max_y > GPU_HEIGHT) max_y = GPU_HEIGHT;
  1315. ;
  1316. L06CF: lda L00A4
  1317. sec
  1318. sbc #$41
  1319. bvs L00DC
  1320. eor #$80
  1321. L00DC: asl a
  1322. ldx #$00
  1323. bcc L06D0
  1324. lda #$40
  1325. sta L00A4
  1326. ;
  1327. ; width = max_x - x;
  1328. ;
  1329. L06D0: lda L00A3
  1330. bpl L00E1
  1331. dex
  1332. L00E1: jsr pushax
  1333. ldy #$06
  1334. ldx #$00
  1335. lda (sp),y
  1336. bpl L00E2
  1337. dex
  1338. L00E2: jsr tossubax
  1339. sta L00A5
  1340. ;
  1341. ; ((unsigned short)y << 7) + x);
  1342. ;
  1343. ldy #$03
  1344. ldx #$00
  1345. lda (sp),y
  1346. cmp #$80
  1347. bcc L00E8
  1348. dex
  1349. L00E8: jsr shlax4
  1350. jsr shlax3
  1351. sta ptr1
  1352. txa
  1353. clc
  1354. adc #$20
  1355. sta ptr1+1
  1356. ldx #$00
  1357. iny
  1358. lda (sp),y
  1359. bpl L00E9
  1360. dex
  1361. L00E9: clc
  1362. adc ptr1
  1363. sta L00A6
  1364. txa
  1365. adc ptr1+1
  1366. sta L00A6+1
  1367. ;
  1368. ; for (j = y; j < max_y; j++) {
  1369. ;
  1370. dey
  1371. lda (sp),y
  1372. sta L00A2
  1373. L00EA: ldx #$00
  1374. lda L00A2
  1375. bpl L00F2
  1376. dex
  1377. L00F2: jsr pushax
  1378. ldx #$00
  1379. lda L00A4
  1380. bpl L00F3
  1381. dex
  1382. L00F3: jsr tosicmp
  1383. bpl L00EB
  1384. ;
  1385. ; memset(vram_row, color, width);
  1386. ;
  1387. lda L00A6
  1388. ldx L00A6+1
  1389. jsr pushax
  1390. ldy #$02
  1391. lda (sp),y
  1392. jsr pusha0
  1393. lda L00A5
  1394. jsr _memset
  1395. ;
  1396. ; vram_row += GPU_STRIDE;
  1397. ;
  1398. lda #$80
  1399. clc
  1400. adc L00A6
  1401. sta L00A6
  1402. bcc L00FC
  1403. inc L00A6+1
  1404. ;
  1405. ; for (j = y; j < max_y; j++) {
  1406. ;
  1407. L00FC: inc L00A2
  1408. bra L00EA
  1409. ;
  1410. ; }
  1411. ;
  1412. L00EB: jmp incsp5
  1413.  
  1414. .endproc
  1415.  
  1416. ; ---------------------------------------------------------------
  1417. ; void __near__ gpu_fill_screen (unsigned char)
  1418. ; ---------------------------------------------------------------
  1419.  
  1420. .segment "CODE"
  1421.  
  1422. .proc _gpu_fill_screen: near
  1423.  
  1424. .segment "BSS"
  1425.  
  1426. L00FE:
  1427. .res 2,$00
  1428.  
  1429. .segment "CODE"
  1430.  
  1431. ;
  1432. ; void gpu_fill_screen(unsigned char color) {
  1433. ;
  1434. jsr pusha
  1435. ;
  1436. ; unsigned char* vram = (unsigned char*)GPU_VRAM_START;
  1437. ;
  1438. ldx #$20
  1439. lda #$00
  1440. stz L00FE
  1441. stx L00FE+1
  1442. ;
  1443. ; memset(vram, color, GPU_STRIDE * GPU_HEIGHT);
  1444. ;
  1445. jsr pushax
  1446. ldy #$02
  1447. lda (sp),y
  1448. jsr pusha0
  1449. ldx #$20
  1450. lda #$00
  1451. jsr _memset
  1452. ;
  1453. ; }
  1454. ;
  1455. jmp incsp1
  1456.  
  1457. .endproc
  1458.  
  1459. ; ---------------------------------------------------------------
  1460. ; int __near__ gpu_abs (int)
  1461. ; ---------------------------------------------------------------
  1462.  
  1463. .segment "CODE"
  1464.  
  1465. .proc _gpu_abs: near
  1466.  
  1467. .segment "CODE"
  1468.  
  1469. ;
  1470. ; int gpu_abs(int v) { return (v < 0) ? -v : v; }
  1471. ;
  1472. jsr pushax
  1473. ldy #$01
  1474. lda (sp),y
  1475. tax
  1476. cpx #$80
  1477. bcc L0107
  1478. ldy #$01
  1479. lda (sp),y
  1480. tax
  1481. lda (sp)
  1482. jsr negax
  1483. jmp incsp2
  1484. L0107: ldy #$01
  1485. lda (sp),y
  1486. tax
  1487. lda (sp)
  1488. jmp incsp2
  1489.  
  1490. .endproc
  1491.  
  1492. ; ---------------------------------------------------------------
  1493. ; void __near__ gpu_swap_coord (__near__ signed char *, __near__ signed char *)
  1494. ; ---------------------------------------------------------------
  1495.  
  1496. .segment "CODE"
  1497.  
  1498. .proc _gpu_swap_coord: near
  1499.  
  1500. .segment "BSS"
  1501.  
  1502. L010C:
  1503. .res 1,$00
  1504.  
  1505. .segment "CODE"
  1506.  
  1507. ;
  1508. ; void gpu_swap_coord(signed char* a, signed char* b) {
  1509. ;
  1510. jsr pushax
  1511. ;
  1512. ; signed char t = *a;
  1513. ;
  1514. ldy #$03
  1515. lda (sp),y
  1516. tax
  1517. dey
  1518. lda (sp),y
  1519. ldy #$00
  1520. jsr ldaidx
  1521. sta L010C
  1522. ;
  1523. ; *a = *b;
  1524. ;
  1525. ldy #$05
  1526. jsr pushwysp
  1527. ldy #$03
  1528. lda (sp),y
  1529. tax
  1530. dey
  1531. lda (sp),y
  1532. ldy #$00
  1533. jsr ldaidx
  1534. jsr staspidx
  1535. ;
  1536. ; *b = t;
  1537. ;
  1538. ldy #$01
  1539. lda (sp),y
  1540. sta ptr1+1
  1541. lda (sp)
  1542. sta ptr1
  1543. lda L010C
  1544. sta (ptr1)
  1545. ;
  1546. ; }
  1547. ;
  1548. jmp incsp4
  1549.  
  1550. .endproc
  1551.  
  1552. ; ---------------------------------------------------------------
  1553. ; void __near__ gpu_draw_line (signed char, signed char, signed char, signed char, unsigned char)
  1554. ; ---------------------------------------------------------------
  1555.  
  1556. .segment "CODE"
  1557.  
  1558. .proc _gpu_draw_line: near
  1559.  
  1560. .segment "BSS"
  1561.  
  1562. L0114:
  1563. .res 1,$00
  1564. L011A:
  1565. .res 1,$00
  1566. L0120:
  1567. .res 1,$00
  1568. L012A:
  1569. .res 1,$00
  1570. L0134:
  1571. .res 2,$00
  1572. L0138:
  1573. .res 2,$00
  1574.  
  1575. .segment "CODE"
  1576.  
  1577. ;
  1578. ; unsigned char color) {
  1579. ;
  1580. jsr pusha
  1581. ;
  1582. ; signed char dx = (signed char)gpu_abs(x1 - x0);
  1583. ;
  1584. ldy #$02
  1585. ldx #$00
  1586. lda (sp),y
  1587. bpl L0117
  1588. dex
  1589. L0117: jsr pushax
  1590. ldy #$06
  1591. ldx #$00
  1592. lda (sp),y
  1593. bpl L0118
  1594. dex
  1595. L0118: jsr tossubax
  1596. jsr _gpu_abs
  1597. cmp #$80
  1598. sta L0114
  1599. ;
  1600. ; signed char dy = (signed char)-gpu_abs(y1 - y0);
  1601. ;
  1602. ldy #$01
  1603. ldx #$00
  1604. lda (sp),y
  1605. bpl L011D
  1606. dex
  1607. L011D: jsr pushax
  1608. ldy #$05
  1609. ldx #$00
  1610. lda (sp),y
  1611. bpl L011E
  1612. dex
  1613. L011E: jsr tossubax
  1614. jsr _gpu_abs
  1615. eor #$FF
  1616. clc
  1617. adc #$01
  1618. cmp #$80
  1619. sta L011A
  1620. ;
  1621. ; signed char sx = (x0 < x1) ? 1 : -1;
  1622. ;
  1623. ldy #$04
  1624. ldx #$00
  1625. lda (sp),y
  1626. bpl L0123
  1627. dex
  1628. L0123: jsr pushax
  1629. ldy #$04
  1630. ldx #$00
  1631. lda (sp),y
  1632. bpl L0124
  1633. dex
  1634. L0124: jsr tosicmp
  1635. bpl L0125
  1636. lda #$01
  1637. bra L06DB
  1638. L0125: lda #$FF
  1639. L06DB: cmp #$80
  1640. sta L0120
  1641. ;
  1642. ; signed char sy = (y0 < y1) ? 1 : -1;
  1643. ;
  1644. ldy #$03
  1645. ldx #$00
  1646. lda (sp),y
  1647. bpl L012D
  1648. dex
  1649. L012D: jsr pushax
  1650. ldy #$03
  1651. ldx #$00
  1652. lda (sp),y
  1653. bpl L012E
  1654. dex
  1655. L012E: jsr tosicmp
  1656. bpl L012F
  1657. lda #$01
  1658. bra L06DC
  1659. L012F: lda #$FF
  1660. L06DC: cmp #$80
  1661. sta L012A
  1662. ;
  1663. ; short err = dx + dy;
  1664. ;
  1665. ldx #$00
  1666. lda L0114
  1667. bpl L0136
  1668. dex
  1669. L0136: sta ptr1
  1670. stx ptr1+1
  1671. ldx #$00
  1672. lda L011A
  1673. bpl L0137
  1674. dex
  1675. L0137: clc
  1676. adc ptr1
  1677. sta L0134
  1678. txa
  1679. adc ptr1+1
  1680. sta L0134+1
  1681. ;
  1682. ; gpu_put_pixel(x0, y0, color);
  1683. ;
  1684. L0139: jsr decsp2
  1685. ldy #$06
  1686. lda (sp),y
  1687. ldy #$01
  1688. sta (sp),y
  1689. ldy #$05
  1690. lda (sp),y
  1691. sta (sp)
  1692. ldy #$02
  1693. lda (sp),y
  1694. jsr _gpu_put_pixel
  1695. ;
  1696. ; if (x0 == x1 && y0 == y1) break;
  1697. ;
  1698. ldy #$04
  1699. ldx #$00
  1700. lda (sp),y
  1701. bpl L0143
  1702. dex
  1703. L0143: sta ptr1
  1704. stx ptr1+1
  1705. ldx #$00
  1706. ldy #$02
  1707. lda (sp),y
  1708. bpl L0144
  1709. dex
  1710. L0144: cpx ptr1+1
  1711. bne L0141
  1712. cmp ptr1
  1713. bne L0141
  1714. iny
  1715. ldx #$00
  1716. lda (sp),y
  1717. bpl L0146
  1718. dex
  1719. L0146: sta ptr1
  1720. stx ptr1+1
  1721. ldx #$00
  1722. ldy #$01
  1723. lda (sp),y
  1724. bpl L0147
  1725. dex
  1726. L0147: cpx ptr1+1
  1727. bne L0141
  1728. cmp ptr1
  1729. bne L0141
  1730. ;
  1731. ; }
  1732. ;
  1733. jmp incsp5
  1734. ;
  1735. ; e2 = 2 * err;
  1736. ;
  1737. L0141: lda L0134
  1738. ldx L0134+1
  1739. stx tmp1
  1740. asl a
  1741. rol tmp1
  1742. ldx tmp1
  1743. sta L0138
  1744. stx L0138+1
  1745. ;
  1746. ; if (e2 >= dy) {
  1747. ;
  1748. jsr pushax
  1749. ldx #$00
  1750. lda L011A
  1751. bpl L014D
  1752. dex
  1753. L014D: jsr tosicmp
  1754. bmi L0156
  1755. ;
  1756. ; err += dy;
  1757. ;
  1758. ldx #$00
  1759. lda L011A
  1760. cmp #$80
  1761. bcc L06D8
  1762. dex
  1763. clc
  1764. L06D8: adc L0134
  1765. sta L0134
  1766. txa
  1767. adc L0134+1
  1768. sta L0134+1
  1769. ;
  1770. ; x0 += sx;
  1771. ;
  1772. lda L0120
  1773. cmp #$80
  1774. ldy #$04
  1775. clc
  1776. adc (sp),y
  1777. sta (sp),y
  1778. ;
  1779. ; if (e2 <= dx) {
  1780. ;
  1781. L0156: lda L0138
  1782. ldx L0138+1
  1783. jsr pushax
  1784. ldx #$00
  1785. lda L0114
  1786. bpl L0159
  1787. dex
  1788. L0159: jsr tosicmp
  1789. beq L06DA
  1790. jpl L0139
  1791. ;
  1792. ; err += dx;
  1793. ;
  1794. L06DA: ldx #$00
  1795. lda L0114
  1796. cmp #$80
  1797. bcc L06D9
  1798. dex
  1799. clc
  1800. L06D9: adc L0134
  1801. sta L0134
  1802. txa
  1803. adc L0134+1
  1804. sta L0134+1
  1805. ;
  1806. ; y0 += sy;
  1807. ;
  1808. lda L012A
  1809. cmp #$80
  1810. ldy #$03
  1811. clc
  1812. adc (sp),y
  1813. sta (sp),y
  1814. jpl L0139
  1815. ;
  1816. ; while (1) {
  1817. ;
  1818. jmp L0139
  1819.  
  1820. .endproc
  1821.  
  1822. ; ---------------------------------------------------------------
  1823. ; void __near__ gpu_draw_tri (signed char, signed char, signed char, signed char, signed char, signed char, unsigned char, unsigned char)
  1824. ; ---------------------------------------------------------------
  1825.  
  1826. .segment "CODE"
  1827.  
  1828. .proc _gpu_draw_tri: near
  1829.  
  1830. .segment "BSS"
  1831.  
  1832. L0164:
  1833. .res 2,$00
  1834. L0165:
  1835. .res 2,$00
  1836. L0166:
  1837. .res 2,$00
  1838. L0167:
  1839. .res 2,$00
  1840. L0168:
  1841. .res 1,$00
  1842. L0169:
  1843. .res 1,$00
  1844. L016A:
  1845. .res 1,$00
  1846. L016B:
  1847. .res 2,$00
  1848. L016C:
  1849. .res 2,$00
  1850. L016D:
  1851. .res 2,$00
  1852. L016E:
  1853. .res 2,$00
  1854.  
  1855. .segment "CODE"
  1856.  
  1857. ;
  1858. ; unsigned char color, unsigned char fill) {
  1859. ;
  1860. jsr pusha
  1861. ;
  1862. ; if (!fill) {
  1863. ;
  1864. lda (sp)
  1865. bne L016F
  1866. ;
  1867. ; gpu_draw_line(x0, y0, x1, y1, color);
  1868. ;
  1869. jsr decsp4
  1870. ldy #$0B
  1871. lda (sp),y
  1872. ldy #$03
  1873. sta (sp),y
  1874. ldy #$0A
  1875. lda (sp),y
  1876. ldy #$02
  1877. sta (sp),y
  1878. ldy #$09
  1879. lda (sp),y
  1880. ldy #$01
  1881. sta (sp),y
  1882. ldy #$08
  1883. lda (sp),y
  1884. sta (sp)
  1885. ldy #$05
  1886. lda (sp),y
  1887. jsr _gpu_draw_line
  1888. ;
  1889. ; gpu_draw_line(x1, y1, x2, y2, color);
  1890. ;
  1891. jsr decsp4
  1892. ldy #$09
  1893. lda (sp),y
  1894. ldy #$03
  1895. sta (sp),y
  1896. ldy #$08
  1897. lda (sp),y
  1898. ldy #$02
  1899. sta (sp),y
  1900. ldy #$07
  1901. lda (sp),y
  1902. ldy #$01
  1903. sta (sp),y
  1904. ldy #$06
  1905. lda (sp),y
  1906. sta (sp)
  1907. dey
  1908. lda (sp),y
  1909. jsr _gpu_draw_line
  1910. ;
  1911. ; gpu_draw_line(x2, y2, x0, y0, color);
  1912. ;
  1913. jsr decsp4
  1914. ldy #$07
  1915. lda (sp),y
  1916. ldy #$03
  1917. sta (sp),y
  1918. ldy #$06
  1919. lda (sp),y
  1920. ldy #$02
  1921. sta (sp),y
  1922. ldy #$0B
  1923. lda (sp),y
  1924. ldy #$01
  1925. sta (sp),y
  1926. ldy #$0A
  1927. lda (sp),y
  1928. sta (sp)
  1929. ldy #$05
  1930. lda (sp),y
  1931. jsr _gpu_draw_line
  1932. ;
  1933. ; return;
  1934. ;
  1935. jmp incsp8
  1936. ;
  1937. ; if (y0 > y1) {
  1938. ;
  1939. L016F: ldy #$06
  1940. ldx #$00
  1941. lda (sp),y
  1942. bpl L0185
  1943. dex
  1944. L0185: jsr pushax
  1945. ldy #$06
  1946. ldx #$00
  1947. lda (sp),y
  1948. bpl L0186
  1949. dex
  1950. L0186: jsr tosicmp
  1951. bmi L0183
  1952. beq L0183
  1953. ;
  1954. ; gpu_swap_coord(&x0, &x1);
  1955. ;
  1956. lda sp
  1957. ldx sp+1
  1958. clc
  1959. adc #$07
  1960. bcc L0189
  1961. inx
  1962. L0189: jsr pushax
  1963. lda sp
  1964. ldx sp+1
  1965. clc
  1966. adc #$07
  1967. bcc L018B
  1968. inx
  1969. L018B: jsr _gpu_swap_coord
  1970. ;
  1971. ; gpu_swap_coord(&y0, &y1);
  1972. ;
  1973. lda sp
  1974. ldx sp+1
  1975. clc
  1976. adc #$06
  1977. bcc L018E
  1978. inx
  1979. L018E: jsr pushax
  1980. lda sp
  1981. ldx sp+1
  1982. clc
  1983. adc #$06
  1984. bcc L0190
  1985. inx
  1986. L0190: jsr _gpu_swap_coord
  1987. ;
  1988. ; if (y0 > y2) {
  1989. ;
  1990. L0183: ldy #$06
  1991. ldx #$00
  1992. lda (sp),y
  1993. bpl L0193
  1994. dex
  1995. L0193: jsr pushax
  1996. ldy #$04
  1997. ldx #$00
  1998. lda (sp),y
  1999. bpl L0194
  2000. dex
  2001. L0194: jsr tosicmp
  2002. bmi L0191
  2003. beq L0191
  2004. ;
  2005. ; gpu_swap_coord(&x0, &x2);
  2006. ;
  2007. lda sp
  2008. ldx sp+1
  2009. clc
  2010. adc #$07
  2011. bcc L0197
  2012. inx
  2013. L0197: jsr pushax
  2014. lda sp
  2015. ldx sp+1
  2016. clc
  2017. adc #$05
  2018. bcc L0199
  2019. inx
  2020. L0199: jsr _gpu_swap_coord
  2021. ;
  2022. ; gpu_swap_coord(&y0, &y2);
  2023. ;
  2024. lda sp
  2025. ldx sp+1
  2026. clc
  2027. adc #$06
  2028. bcc L019C
  2029. inx
  2030. L019C: jsr pushax
  2031. lda sp
  2032. ldx sp+1
  2033. clc
  2034. adc #$04
  2035. bcc L019E
  2036. inx
  2037. L019E: jsr _gpu_swap_coord
  2038. ;
  2039. ; if (y1 > y2) {
  2040. ;
  2041. L0191: ldy #$04
  2042. ldx #$00
  2043. lda (sp),y
  2044. bpl L01A1
  2045. dex
  2046. L01A1: jsr pushax
  2047. ldy #$04
  2048. ldx #$00
  2049. lda (sp),y
  2050. bpl L01A2
  2051. dex
  2052. L01A2: jsr tosicmp
  2053. bmi L019F
  2054. beq L019F
  2055. ;
  2056. ; gpu_swap_coord(&x1, &x2);
  2057. ;
  2058. lda sp
  2059. ldx sp+1
  2060. clc
  2061. adc #$05
  2062. bcc L01A5
  2063. inx
  2064. L01A5: jsr pushax
  2065. lda sp
  2066. ldx sp+1
  2067. clc
  2068. adc #$05
  2069. bcc L01A7
  2070. inx
  2071. L01A7: jsr _gpu_swap_coord
  2072. ;
  2073. ; gpu_swap_coord(&y1, &y2);
  2074. ;
  2075. lda sp
  2076. ldx sp+1
  2077. clc
  2078. adc #$04
  2079. bcc L01AA
  2080. inx
  2081. L01AA: jsr pushax
  2082. lda sp
  2083. ldx sp+1
  2084. clc
  2085. adc #$04
  2086. bcc L01AC
  2087. inx
  2088. L01AC: jsr _gpu_swap_coord
  2089. ;
  2090. ; if (y2 < 0 || y0 >= GPU_HEIGHT) return;
  2091. ;
  2092. L019F: ldy #$02
  2093. lda (sp),y
  2094. asl a
  2095. bcc L06EE
  2096. ;
  2097. ; }
  2098. ;
  2099. jmp incsp8
  2100. ;
  2101. ; if (y2 < 0 || y0 >= GPU_HEIGHT) return;
  2102. ;
  2103. L06EE: ldy #$06
  2104. lda (sp),y
  2105. sec
  2106. sbc #$40
  2107. bvs L01B1
  2108. eor #$80
  2109. L01B1: bpl L06EF
  2110. ;
  2111. ; }
  2112. ;
  2113. jmp incsp8
  2114. ;
  2115. ; x_long = TO_FIXED(x0);
  2116. ;
  2117. L06EF: iny
  2118. lda (sp),y
  2119. sta L0164+1
  2120. stz L0164
  2121. ;
  2122. ; dx_long = 0;
  2123. ;
  2124. ldx #$00
  2125. stz L0166
  2126. stz L0166+1
  2127. ;
  2128. ; if (y2 != y0) dx_long = TO_FIXED(x2 - x0) / (y2 - y0);
  2129. ;
  2130. ldy #$02
  2131. lda (sp),y
  2132. bpl L01BC
  2133. dex
  2134. L01BC: sta ptr1
  2135. stx ptr1+1
  2136. ldx #$00
  2137. ldy #$06
  2138. lda (sp),y
  2139. bpl L01BD
  2140. dex
  2141. L01BD: cpx ptr1+1
  2142. bne L06ED
  2143. cmp ptr1
  2144. beq L01BA
  2145. L06ED: ldy #$03
  2146. ldx #$00
  2147. lda (sp),y
  2148. bpl L01C2
  2149. dex
  2150. L01C2: jsr pushax
  2151. ldy #$09
  2152. ldx #$00
  2153. lda (sp),y
  2154. bpl L01C3
  2155. dex
  2156. L01C3: jsr tossubax
  2157. tax
  2158. lda #$00
  2159. jsr pushax
  2160. ldy #$04
  2161. tax
  2162. lda (sp),y
  2163. bpl L01C5
  2164. dex
  2165. L01C5: jsr pushax
  2166. ldy #$0A
  2167. ldx #$00
  2168. lda (sp),y
  2169. bpl L01C6
  2170. dex
  2171. L01C6: jsr tossubax
  2172. jsr tosdivax
  2173. sta L0166
  2174. stx L0166+1
  2175. ;
  2176. ; if (y1 > y0) {
  2177. ;
  2178. L01BA: ldy #$04
  2179. ldx #$00
  2180. lda (sp),y
  2181. bpl L01C9
  2182. dex
  2183. L01C9: jsr pushax
  2184. ldy #$08
  2185. ldx #$00
  2186. lda (sp),y
  2187. bpl L01CA
  2188. dex
  2189. L01CA: jsr tosicmp
  2190. jmi L01C7
  2191. jeq L01C7
  2192. ;
  2193. ; x_short = TO_FIXED(x0);
  2194. ;
  2195. ldy #$07
  2196. lda (sp),y
  2197. sta L0165+1
  2198. stz L0165
  2199. ;
  2200. ; dx_short = TO_FIXED(x1 - x0) / (y1 - y0);
  2201. ;
  2202. ldy #$05
  2203. ldx #$00
  2204. lda (sp),y
  2205. bpl L01D4
  2206. dex
  2207. L01D4: jsr pushax
  2208. ldy #$09
  2209. ldx #$00
  2210. lda (sp),y
  2211. bpl L01D5
  2212. dex
  2213. L01D5: jsr tossubax
  2214. tax
  2215. lda #$00
  2216. jsr pushax
  2217. ldy #$06
  2218. tax
  2219. lda (sp),y
  2220. bpl L01D7
  2221. dex
  2222. L01D7: jsr pushax
  2223. ldy #$0A
  2224. ldx #$00
  2225. lda (sp),y
  2226. bpl L01D8
  2227. dex
  2228. L01D8: jsr tossubax
  2229. jsr tosdivax
  2230. sta L0167
  2231. stx L0167+1
  2232. ;
  2233. ; start_y = y0;
  2234. ;
  2235. ldy #$06
  2236. lda (sp),y
  2237. sta L0169
  2238. ;
  2239. ; end_y = y1;
  2240. ;
  2241. ldy #$04
  2242. lda (sp),y
  2243. sta L016A
  2244. ;
  2245. ; if (start_y < 0) {
  2246. ;
  2247. lda L0169
  2248. asl a
  2249. bcc L06E6
  2250. ;
  2251. ; x_long += dx_long * (-start_y);
  2252. ;
  2253. lda L0166
  2254. ldx L0166+1
  2255. jsr pushax
  2256. ldx #$00
  2257. lda L0169
  2258. bpl L01E5
  2259. dex
  2260. L01E5: jsr negax
  2261. jsr tosmulax
  2262. clc
  2263. adc L0164
  2264. sta L0164
  2265. txa
  2266. adc L0164+1
  2267. sta L0164+1
  2268. ;
  2269. ; x_short += dx_short * (-start_y);
  2270. ;
  2271. lda L0167
  2272. ldx L0167+1
  2273. jsr pushax
  2274. ldx #$00
  2275. lda L0169
  2276. bpl L01E9
  2277. dex
  2278. L01E9: jsr negax
  2279. jsr tosmulax
  2280. clc
  2281. adc L0165
  2282. sta L0165
  2283. txa
  2284. adc L0165+1
  2285. sta L0165+1
  2286. ;
  2287. ; start_y = 0;
  2288. ;
  2289. stz L0169
  2290. ;
  2291. ; if (end_y > GPU_HEIGHT) end_y = GPU_HEIGHT;
  2292. ;
  2293. L06E6: lda L016A
  2294. sec
  2295. sbc #$41
  2296. bvs L01EF
  2297. eor #$80
  2298. L01EF: bpl L06E7
  2299. lda #$40
  2300. sta L016A
  2301. ;
  2302. ; for (y = start_y; y < end_y; y++) {
  2303. ;
  2304. L06E7: lda L0169
  2305. sta L0168
  2306. L01F2: ldx #$00
  2307. lda L0168
  2308. bpl L01FA
  2309. dex
  2310. L01FA: jsr pushax
  2311. ldx #$00
  2312. lda L016A
  2313. bpl L01FB
  2314. dex
  2315. L01FB: jsr tosicmp
  2316. jpl L022B
  2317. ;
  2318. ; xl = FROM_FIXED(x_long);
  2319. ;
  2320. ldx L0164+1
  2321. cpx #$80
  2322. txa
  2323. ldx #$00
  2324. bcc L0202
  2325. dex
  2326. L0202: sta L016B
  2327. stx L016B+1
  2328. ;
  2329. ; xr = FROM_FIXED(x_short);
  2330. ;
  2331. ldx L0165+1
  2332. cpx #$80
  2333. txa
  2334. ldx #$00
  2335. bcc L0207
  2336. dex
  2337. L0207: sta L016C
  2338. stx L016C+1
  2339. ;
  2340. ; if (xl > xr) {
  2341. ;
  2342. lda L016B
  2343. ldx L016B+1
  2344. jsr pushax
  2345. lda L016C
  2346. ldx L016C+1
  2347. jsr tosicmp
  2348. bmi L0208
  2349. beq L0208
  2350. ;
  2351. ; t = xl;
  2352. ;
  2353. lda L016B+1
  2354. sta L016D+1
  2355. lda L016B
  2356. sta L016D
  2357. ;
  2358. ; xl = xr;
  2359. ;
  2360. lda L016C+1
  2361. sta L016B+1
  2362. lda L016C
  2363. sta L016B
  2364. ;
  2365. ; xr = t;
  2366. ;
  2367. lda L016D+1
  2368. sta L016C+1
  2369. lda L016D
  2370. sta L016C
  2371. ;
  2372. ; if (xl < 0) xl = 0;
  2373. ;
  2374. L0208: ldx L016B+1
  2375. cpx #$80
  2376. bcc L0210
  2377. stz L016B
  2378. stz L016B+1
  2379. ;
  2380. ; if (xr >= GPU_WIDTH) xr = GPU_WIDTH - 1;
  2381. ;
  2382. L0210: lda L016C
  2383. cmp #$64
  2384. lda L016C+1
  2385. sbc #$00
  2386. bvs L0216
  2387. eor #$80
  2388. L0216: bpl L0214
  2389. lda #$63
  2390. sta L016C
  2391. stz L016C+1
  2392. ;
  2393. ; if (xl <= xr) {
  2394. ;
  2395. L0214: lda L016B
  2396. ldx L016B+1
  2397. jsr pushax
  2398. lda L016C
  2399. ldx L016C+1
  2400. jsr tosicmp
  2401. beq L06E3
  2402. bpl L0219
  2403. ;
  2404. ; offset = ((unsigned short)y << 7) + xl;
  2405. ;
  2406. L06E3: ldx #$00
  2407. lda L0168
  2408. cmp #$80
  2409. bcc L021F
  2410. dex
  2411. L021F: jsr shlax4
  2412. jsr shlax3
  2413. clc
  2414. adc L016B
  2415. pha
  2416. txa
  2417. adc L016B+1
  2418. tax
  2419. pla
  2420. sta L016E
  2421. stx L016E+1
  2422. ;
  2423. ; memset((void*)(unsigned long)(GPU_VRAM_START + offset), color,
  2424. ;
  2425. pha
  2426. txa
  2427. clc
  2428. adc #$20
  2429. tax
  2430. pla
  2431. jsr pushax
  2432. ldy #$03
  2433. lda (sp),y
  2434. jsr pusha0
  2435. ;
  2436. ; xr - xl + 1);
  2437. ;
  2438. lda L016C
  2439. sec
  2440. sbc L016B
  2441. pha
  2442. lda L016C+1
  2443. sbc L016B+1
  2444. tax
  2445. pla
  2446. ina
  2447. bne L0225
  2448. inx
  2449. L0225: jsr _memset
  2450. ;
  2451. ; x_long += dx_long;
  2452. ;
  2453. L0219: lda L0166
  2454. clc
  2455. adc L0164
  2456. sta L0164
  2457. lda L0166+1
  2458. adc L0164+1
  2459. sta L0164+1
  2460. ;
  2461. ; x_short += dx_short;
  2462. ;
  2463. lda L0167
  2464. clc
  2465. adc L0165
  2466. sta L0165
  2467. lda L0167+1
  2468. adc L0165+1
  2469. sta L0165+1
  2470. ;
  2471. ; for (y = start_y; y < end_y; y++) {
  2472. ;
  2473. inc L0168
  2474. jmp L01F2
  2475. ;
  2476. ; if (y0 < 0) {
  2477. ;
  2478. L01C7: ldy #$06
  2479. lda (sp),y
  2480. asl a
  2481. bcc L022B
  2482. ;
  2483. ; x_long += dx_long * (-y0);
  2484. ;
  2485. lda L0166
  2486. ldx L0166+1
  2487. jsr pushax
  2488. ldy #$08
  2489. ldx #$00
  2490. lda (sp),y
  2491. bpl L0231
  2492. dex
  2493. L0231: jsr negax
  2494. jsr tosmulax
  2495. clc
  2496. adc L0164
  2497. sta L0164
  2498. txa
  2499. adc L0164+1
  2500. sta L0164+1
  2501. ;
  2502. ; if (y2 > y1) {
  2503. ;
  2504. L022B: ldy #$02
  2505. ldx #$00
  2506. lda (sp),y
  2507. bpl L0234
  2508. dex
  2509. L0234: jsr pushax
  2510. ldy #$06
  2511. ldx #$00
  2512. lda (sp),y
  2513. bpl L0235
  2514. dex
  2515. L0235: jsr tosicmp
  2516. bpl L06F0
  2517. ;
  2518. ; }
  2519. ;
  2520. jmp incsp8
  2521. ;
  2522. ; if (y2 > y1) {
  2523. ;
  2524. L06F0: bne L06F1
  2525. ;
  2526. ; }
  2527. ;
  2528. jmp incsp8
  2529. ;
  2530. ; x_short = TO_FIXED(x1);
  2531. ;
  2532. L06F1: ldy #$05
  2533. lda (sp),y
  2534. sta L0165+1
  2535. stz L0165
  2536. ;
  2537. ; dx_short = TO_FIXED(x2 - x1) / (y2 - y1);
  2538. ;
  2539. ldy #$03
  2540. ldx #$00
  2541. lda (sp),y
  2542. bpl L023F
  2543. dex
  2544. L023F: jsr pushax
  2545. ldy #$07
  2546. ldx #$00
  2547. lda (sp),y
  2548. bpl L0240
  2549. dex
  2550. L0240: jsr tossubax
  2551. tax
  2552. lda #$00
  2553. jsr pushax
  2554. ldy #$04
  2555. tax
  2556. lda (sp),y
  2557. bpl L0242
  2558. dex
  2559. L0242: jsr pushax
  2560. ldy #$08
  2561. ldx #$00
  2562. lda (sp),y
  2563. bpl L0243
  2564. dex
  2565. L0243: jsr tossubax
  2566. jsr tosdivax
  2567. sta L0167
  2568. stx L0167+1
  2569. ;
  2570. ; start_y = y1;
  2571. ;
  2572. ldy #$04
  2573. lda (sp),y
  2574. sta L0169
  2575. ;
  2576. ; end_y = y2;
  2577. ;
  2578. ldy #$02
  2579. lda (sp),y
  2580. sta L016A
  2581. ;
  2582. ; if (start_y < 0) {
  2583. ;
  2584. lda L0169
  2585. asl a
  2586. bcc L024A
  2587. ;
  2588. ; x_long += dx_long * (0 - start_y);
  2589. ;
  2590. lda L0166
  2591. ldx L0166+1
  2592. jsr pushax
  2593. jsr push0
  2594. lda L0169
  2595. bpl L0250
  2596. ldx #$FF
  2597. L0250: jsr tossubax
  2598. jsr tosmulax
  2599. clc
  2600. adc L0164
  2601. sta L0164
  2602. txa
  2603. adc L0164+1
  2604. sta L0164+1
  2605. ;
  2606. ; x_short += dx_short * (0 - start_y);
  2607. ;
  2608. lda L0167
  2609. ldx L0167+1
  2610. jsr pushax
  2611. jsr push0
  2612. lda L0169
  2613. bpl L0254
  2614. ldx #$FF
  2615. L0254: jsr tossubax
  2616. jsr tosmulax
  2617. clc
  2618. adc L0165
  2619. sta L0165
  2620. txa
  2621. adc L0165+1
  2622. sta L0165+1
  2623. ;
  2624. ; start_y = 0;
  2625. ;
  2626. stz L0169
  2627. ;
  2628. ; if (y0 == y1 && y0 < 0) {
  2629. ;
  2630. L024A: ldy #$06
  2631. ldx #$00
  2632. lda (sp),y
  2633. bpl L0259
  2634. dex
  2635. L0259: sta ptr1
  2636. stx ptr1+1
  2637. ldx #$00
  2638. ldy #$04
  2639. lda (sp),y
  2640. bpl L025A
  2641. dex
  2642. L025A: cpx ptr1+1
  2643. bne L06EA
  2644. cmp ptr1
  2645. bne L06EA
  2646. ldy #$06
  2647. lda (sp),y
  2648. asl a
  2649. bcc L06EA
  2650. ;
  2651. ; x_long += dx_long * (-y0);
  2652. ;
  2653. lda L0166
  2654. ldx L0166+1
  2655. jsr pushax
  2656. ldy #$08
  2657. ldx #$00
  2658. lda (sp),y
  2659. bpl L0261
  2660. dex
  2661. L0261: jsr negax
  2662. jsr tosmulax
  2663. clc
  2664. adc L0164
  2665. sta L0164
  2666. txa
  2667. adc L0164+1
  2668. sta L0164+1
  2669. ;
  2670. ; if (end_y > GPU_HEIGHT) end_y = GPU_HEIGHT;
  2671. ;
  2672. L06EA: lda L016A
  2673. sec
  2674. sbc #$41
  2675. bvs L0265
  2676. eor #$80
  2677. L0265: bpl L06EB
  2678. lda #$40
  2679. sta L016A
  2680. ;
  2681. ; for (y = start_y; y < end_y; y++) {
  2682. ;
  2683. L06EB: lda L0169
  2684. sta L0168
  2685. L0268: ldx #$00
  2686. lda L0168
  2687. bpl L0270
  2688. dex
  2689. L0270: jsr pushax
  2690. ldx #$00
  2691. lda L016A
  2692. bpl L0271
  2693. dex
  2694. L0271: jsr tosicmp
  2695. bmi L06F2
  2696. ;
  2697. ; }
  2698. ;
  2699. jmp incsp8
  2700. ;
  2701. ; xl = FROM_FIXED(x_long);
  2702. ;
  2703. L06F2: ldx L0164+1
  2704. cpx #$80
  2705. txa
  2706. ldx #$00
  2707. bcc L0278
  2708. dex
  2709. L0278: sta L016B
  2710. stx L016B+1
  2711. ;
  2712. ; xr = FROM_FIXED(x_short);
  2713. ;
  2714. ldx L0165+1
  2715. cpx #$80
  2716. txa
  2717. ldx #$00
  2718. bcc L027D
  2719. dex
  2720. L027D: sta L016C
  2721. stx L016C+1
  2722. ;
  2723. ; if (xl > xr) {
  2724. ;
  2725. lda L016B
  2726. ldx L016B+1
  2727. jsr pushax
  2728. lda L016C
  2729. ldx L016C+1
  2730. jsr tosicmp
  2731. bmi L027E
  2732. beq L027E
  2733. ;
  2734. ; t = xl;
  2735. ;
  2736. lda L016B+1
  2737. sta L016D+1
  2738. lda L016B
  2739. sta L016D
  2740. ;
  2741. ; xl = xr;
  2742. ;
  2743. lda L016C+1
  2744. sta L016B+1
  2745. lda L016C
  2746. sta L016B
  2747. ;
  2748. ; xr = t;
  2749. ;
  2750. lda L016D+1
  2751. sta L016C+1
  2752. lda L016D
  2753. sta L016C
  2754. ;
  2755. ; if (xl < 0) xl = 0;
  2756. ;
  2757. L027E: ldx L016B+1
  2758. cpx #$80
  2759. bcc L0286
  2760. stz L016B
  2761. stz L016B+1
  2762. ;
  2763. ; if (xr >= GPU_WIDTH) xr = GPU_WIDTH - 1;
  2764. ;
  2765. L0286: lda L016C
  2766. cmp #$64
  2767. lda L016C+1
  2768. sbc #$00
  2769. bvs L028C
  2770. eor #$80
  2771. L028C: bpl L028A
  2772. lda #$63
  2773. sta L016C
  2774. stz L016C+1
  2775. ;
  2776. ; if (xl <= xr) {
  2777. ;
  2778. L028A: lda L016B
  2779. ldx L016B+1
  2780. jsr pushax
  2781. lda L016C
  2782. ldx L016C+1
  2783. jsr tosicmp
  2784. beq L06E4
  2785. bpl L028F
  2786. ;
  2787. ; offset = ((unsigned short)y << 7) + xl;
  2788. ;
  2789. L06E4: ldx #$00
  2790. lda L0168
  2791. cmp #$80
  2792. bcc L0295
  2793. dex
  2794. L0295: jsr shlax4
  2795. jsr shlax3
  2796. clc
  2797. adc L016B
  2798. pha
  2799. txa
  2800. adc L016B+1
  2801. tax
  2802. pla
  2803. sta L016E
  2804. stx L016E+1
  2805. ;
  2806. ; memset((void*)(unsigned long)(GPU_VRAM_START + offset), color,
  2807. ;
  2808. pha
  2809. txa
  2810. clc
  2811. adc #$20
  2812. tax
  2813. pla
  2814. jsr pushax
  2815. ldy #$03
  2816. lda (sp),y
  2817. jsr pusha0
  2818. ;
  2819. ; xr - xl + 1);
  2820. ;
  2821. lda L016C
  2822. sec
  2823. sbc L016B
  2824. pha
  2825. lda L016C+1
  2826. sbc L016B+1
  2827. tax
  2828. pla
  2829. ina
  2830. bne L029B
  2831. inx
  2832. L029B: jsr _memset
  2833. ;
  2834. ; x_long += dx_long;
  2835. ;
  2836. L028F: lda L0166
  2837. clc
  2838. adc L0164
  2839. sta L0164
  2840. lda L0166+1
  2841. adc L0164+1
  2842. sta L0164+1
  2843. ;
  2844. ; x_short += dx_short;
  2845. ;
  2846. lda L0167
  2847. clc
  2848. adc L0165
  2849. sta L0165
  2850. lda L0167+1
  2851. adc L0165+1
  2852. sta L0165+1
  2853. ;
  2854. ; for (y = start_y; y < end_y; y++) {
  2855. ;
  2856. inc L0168
  2857. jmp L0268
  2858.  
  2859. .endproc
  2860.  
  2861. ; ---------------------------------------------------------------
  2862. ; void __near__ GPUdelay (unsigned int)
  2863. ; ---------------------------------------------------------------
  2864.  
  2865. .segment "CODE"
  2866.  
  2867. .proc _GPUdelay: near
  2868.  
  2869. .segment "BSS"
  2870.  
  2871. L02A1:
  2872. .res 2,$00
  2873. L02A2:
  2874. .res 2,$00
  2875.  
  2876. .segment "CODE"
  2877.  
  2878. ;
  2879. ; void GPUdelay(unsigned int ms) {
  2880. ;
  2881. jsr pushax
  2882. ;
  2883. ; for (i = 0; i < ms; i++) {
  2884. ;
  2885. stz L02A1
  2886. stz L02A1+1
  2887. L02A3: lda L02A1
  2888. cmp (sp)
  2889. lda L02A1+1
  2890. ldy #$01
  2891. sbc (sp),y
  2892. bcs L02A4
  2893. ;
  2894. ; for (j = 0; j < GPU_ITERATIONS_PER_MS; j++) {
  2895. ;
  2896. stz L02A2
  2897. stz L02A2+1
  2898. L02AC: lda L02A2+1
  2899. cmp #$00
  2900. bne L02B3
  2901. lda L02A2
  2902. cmp #$13
  2903. L02B3: bcs L02A5
  2904. lda L02A2
  2905. ldx L02A2+1
  2906. ina
  2907. bne L02B5
  2908. inx
  2909. L02B5: sta L02A2
  2910. stx L02A2+1
  2911. bra L02AC
  2912. ;
  2913. ; for (i = 0; i < ms; i++) {
  2914. ;
  2915. L02A5: lda L02A1
  2916. ldx L02A1+1
  2917. ina
  2918. bne L02AB
  2919. inx
  2920. L02AB: sta L02A1
  2921. stx L02A1+1
  2922. bra L02A3
  2923. ;
  2924. ; }
  2925. ;
  2926. L02A4: jmp incsp2
  2927.  
  2928. .endproc
  2929.  
  2930. ; ---------------------------------------------------------------
  2931. ; void __near__ gpu_test_pattern (void)
  2932. ; ---------------------------------------------------------------
  2933.  
  2934. .segment "CODE"
  2935.  
  2936. .proc _gpu_test_pattern: near
  2937.  
  2938. .segment "BSS"
  2939.  
  2940. L02B7:
  2941. .res 1,$00
  2942. L02B8:
  2943. .res 1,$00
  2944. L02B9:
  2945. .res 1,$00
  2946.  
  2947. .segment "CODE"
  2948.  
  2949. ;
  2950. ; for (r = 0; r < GPU_HEIGHT; r++) {
  2951. ;
  2952. stz L02B7
  2953. L06F4: lda L02B7
  2954. cmp #$40
  2955. bcs L02BB
  2956. ;
  2957. ; row_color = r * 4;
  2958. ;
  2959. asl a
  2960. asl a
  2961. sta L02B9
  2962. ;
  2963. ; for (c = 0; c < GPU_WIDTH; c++) {
  2964. ;
  2965. stz L02B8
  2966. L06F5: lda L02B8
  2967. cmp #$64
  2968. bcs L06F6
  2969. ;
  2970. ; gpu_put_pixel(c, r, row_color + c);
  2971. ;
  2972. jsr decsp2
  2973. lda L02B8
  2974. ldy #$01
  2975. sta (sp),y
  2976. lda L02B7
  2977. sta (sp)
  2978. lda L02B9
  2979. clc
  2980. adc L02B8
  2981. jsr _gpu_put_pixel
  2982. ;
  2983. ; for (c = 0; c < GPU_WIDTH; c++) {
  2984. ;
  2985. inc L02B8
  2986. bra L06F5
  2987. ;
  2988. ; for (r = 0; r < GPU_HEIGHT; r++) {
  2989. ;
  2990. L06F6: inc L02B7
  2991. bra L06F4
  2992. ;
  2993. ; }
  2994. ;
  2995. L02BB: rts
  2996.  
  2997. .endproc
  2998.  
  2999. ; ---------------------------------------------------------------
  3000. ; void __near__ lcd_send_nibble (unsigned char, unsigned char)
  3001. ; ---------------------------------------------------------------
  3002.  
  3003. .segment "CODE"
  3004.  
  3005. .proc _lcd_send_nibble: near
  3006.  
  3007. .segment "CODE"
  3008.  
  3009. ;
  3010. ; void lcd_send_nibble(unsigned char data, unsigned char mode) {
  3011. ;
  3012. jsr pusha
  3013. ;
  3014. ; data &= 0x0F; // Ensure only low 4 bits
  3015. ;
  3016. ldy #$01
  3017. lda (sp),y
  3018. and #$0F
  3019. sta (sp),y
  3020. ;
  3021. ; PORTB = data | mode | E;
  3022. ;
  3023. lda (sp)
  3024. ldy #$01
  3025. ora (sp),y
  3026. ora #$40
  3027. sta $6000
  3028. ;
  3029. ; PORTB = data | mode;
  3030. ;
  3031. lda (sp)
  3032. ldy #$01
  3033. ora (sp),y
  3034. sta $6000
  3035. ;
  3036. ; }
  3037. ;
  3038. jmp incsp2
  3039.  
  3040. .endproc
  3041.  
  3042. ; ---------------------------------------------------------------
  3043. ; void __near__ lcd_instruction (unsigned char)
  3044. ; ---------------------------------------------------------------
  3045.  
  3046. .segment "CODE"
  3047.  
  3048. .proc _lcd_instruction: near
  3049.  
  3050. .segment "CODE"
  3051.  
  3052. ;
  3053. ; void lcd_instruction(unsigned char cmd) {
  3054. ;
  3055. jsr pusha
  3056. ;
  3057. ; lcd_send_nibble(cmd >> 4, 0); // High nibble
  3058. ;
  3059. lda (sp)
  3060. lsr a
  3061. lsr a
  3062. lsr a
  3063. lsr a
  3064. jsr pusha
  3065. lda #$00
  3066. jsr _lcd_send_nibble
  3067. ;
  3068. ; lcd_send_nibble(cmd, 0); // Low nibble
  3069. ;
  3070. lda (sp)
  3071. jsr pusha
  3072. lda #$00
  3073. jsr _lcd_send_nibble
  3074. ;
  3075. ; }
  3076. ;
  3077. jmp incsp1
  3078.  
  3079. .endproc
  3080.  
  3081. ; ---------------------------------------------------------------
  3082. ; void __near__ lcd_print_char (unsigned char)
  3083. ; ---------------------------------------------------------------
  3084.  
  3085. .segment "CODE"
  3086.  
  3087. .proc _lcd_print_char: near
  3088.  
  3089. .segment "CODE"
  3090.  
  3091. ;
  3092. ; void lcd_print_char(unsigned char c) {
  3093. ;
  3094. jsr pusha
  3095. ;
  3096. ; lcd_send_nibble(c >> 4, RS);
  3097. ;
  3098. lda (sp)
  3099. lsr a
  3100. lsr a
  3101. lsr a
  3102. lsr a
  3103. jsr pusha
  3104. lda #$10
  3105. jsr _lcd_send_nibble
  3106. ;
  3107. ; lcd_send_nibble(c, RS);
  3108. ;
  3109. lda (sp)
  3110. jsr pusha
  3111. lda #$10
  3112. jsr _lcd_send_nibble
  3113. ;
  3114. ; }
  3115. ;
  3116. jmp incsp1
  3117.  
  3118. .endproc
  3119.  
  3120. ; ---------------------------------------------------------------
  3121. ; void __near__ lcd_clear (void)
  3122. ; ---------------------------------------------------------------
  3123.  
  3124. .segment "CODE"
  3125.  
  3126. .proc _lcd_clear: near
  3127.  
  3128. .segment "CODE"
  3129.  
  3130. ;
  3131. ; void lcd_clear(void) { lcd_instruction(0x01); }
  3132. ;
  3133. lda #$01
  3134. jmp _lcd_instruction
  3135.  
  3136. .endproc
  3137.  
  3138. ; ---------------------------------------------------------------
  3139. ; void __near__ lcd_newline (void)
  3140. ; ---------------------------------------------------------------
  3141.  
  3142. .segment "CODE"
  3143.  
  3144. .proc _lcd_newline: near
  3145.  
  3146. .segment "CODE"
  3147.  
  3148. ;
  3149. ; void lcd_newline(void) { lcd_print_char('\n'); }
  3150. ;
  3151. lda #$0A
  3152. jmp _lcd_print_char
  3153.  
  3154. .endproc
  3155.  
  3156. ; ---------------------------------------------------------------
  3157. ; void __near__ lcd_init (void)
  3158. ; ---------------------------------------------------------------
  3159.  
  3160. .segment "CODE"
  3161.  
  3162. .proc _lcd_init: near
  3163.  
  3164. .segment "CODE"
  3165.  
  3166. ;
  3167. ; DDRB = 0xFF;
  3168. ;
  3169. lda #$FF
  3170. sta $6002
  3171. ;
  3172. ; lcd_send_nibble(0x03, 0);
  3173. ;
  3174. lda #$03
  3175. jsr pusha
  3176. lda #$00
  3177. jsr _lcd_send_nibble
  3178. ;
  3179. ; lcd_send_nibble(0x03, 0);
  3180. ;
  3181. lda #$03
  3182. jsr pusha
  3183. lda #$00
  3184. jsr _lcd_send_nibble
  3185. ;
  3186. ; lcd_send_nibble(0x03, 0);
  3187. ;
  3188. lda #$03
  3189. jsr pusha
  3190. lda #$00
  3191. jsr _lcd_send_nibble
  3192. ;
  3193. ; lcd_send_nibble(0x02, 0);
  3194. ;
  3195. lda #$02
  3196. jsr pusha
  3197. lda #$00
  3198. jsr _lcd_send_nibble
  3199. ;
  3200. ; lcd_instruction(0x28);
  3201. ;
  3202. lda #$28
  3203. jsr _lcd_instruction
  3204. ;
  3205. ; lcd_instruction(0x0E);
  3206. ;
  3207. lda #$0E
  3208. jsr _lcd_instruction
  3209. ;
  3210. ; lcd_instruction(0x06);
  3211. ;
  3212. lda #$06
  3213. jsr _lcd_instruction
  3214. ;
  3215. ; lcd_clear();
  3216. ;
  3217. jmp _lcd_clear
  3218.  
  3219. .endproc
  3220.  
  3221. ; ---------------------------------------------------------------
  3222. ; void __near__ lcd_print (__near__ const unsigned char *)
  3223. ; ---------------------------------------------------------------
  3224.  
  3225. .segment "CODE"
  3226.  
  3227. .proc _lcd_print: near
  3228.  
  3229. .segment "CODE"
  3230.  
  3231. ;
  3232. ; void lcd_print(const char* str) {
  3233. ;
  3234. jsr pushax
  3235. ;
  3236. ; while (*str) {
  3237. ;
  3238. bra L0307
  3239. ;
  3240. ; lcd_print_char(*str++);
  3241. ;
  3242. L0305: ldy #$01
  3243. lda (sp),y
  3244. tax
  3245. lda (sp)
  3246. sta regsave
  3247. stx regsave+1
  3248. ina
  3249. bne L030B
  3250. inx
  3251. L030B: jsr stax0sp
  3252. lda (regsave)
  3253. jsr _lcd_print_char
  3254. ;
  3255. ; while (*str) {
  3256. ;
  3257. L0307: ldy #$01
  3258. lda (sp),y
  3259. sta ptr1+1
  3260. lda (sp)
  3261. sta ptr1
  3262. lda (ptr1)
  3263. bne L0305
  3264. ;
  3265. ; }
  3266. ;
  3267. jmp incsp2
  3268.  
  3269. .endproc
  3270.  
  3271. ; ---------------------------------------------------------------
  3272. ; void __near__ lcd_print_number (unsigned int)
  3273. ; ---------------------------------------------------------------
  3274.  
  3275. .segment "CODE"
  3276.  
  3277. .proc _lcd_print_number: near
  3278.  
  3279. .segment "BSS"
  3280.  
  3281. L030D:
  3282. .res 1,$00
  3283. L030E:
  3284. .res 1,$00
  3285. L030F:
  3286. .res 1,$00
  3287. L0310:
  3288. .res 1,$00
  3289.  
  3290. .segment "CODE"
  3291.  
  3292. ;
  3293. ; void lcd_print_number(unsigned int num) {
  3294. ;
  3295. jsr pushax
  3296. ;
  3297. ; hundreds = num / 100;
  3298. ;
  3299. jsr pushw0sp
  3300. lda #$64
  3301. jsr tosudiva0
  3302. sta L030D
  3303. ;
  3304. ; remainder = num % 100;
  3305. ;
  3306. jsr pushw0sp
  3307. lda #$64
  3308. jsr tosumoda0
  3309. sta L030E
  3310. ;
  3311. ; tens = remainder / 10;
  3312. ;
  3313. lda L030E
  3314. jsr pusha0
  3315. lda #$0A
  3316. jsr tosudiva0
  3317. sta L030F
  3318. ;
  3319. ; units = remainder % 10;
  3320. ;
  3321. lda L030E
  3322. jsr pusha0
  3323. lda #$0A
  3324. jsr tosumoda0
  3325. sta L0310
  3326. ;
  3327. ; if (hundreds > 0) {
  3328. ;
  3329. lda L030D
  3330. beq L06F8
  3331. ;
  3332. ; lcd_print_char('0' + hundreds);
  3333. ;
  3334. clc
  3335. adc #$30
  3336. jsr _lcd_print_char
  3337. ;
  3338. ; } else if (tens > 0) {
  3339. ;
  3340. bra L06FF
  3341. L06F8: lda L030F
  3342. beq L06F9
  3343. ;
  3344. ; lcd_print_char('0' + tens);
  3345. ;
  3346. L06FF: lda L030F
  3347. clc
  3348. adc #$30
  3349. jsr _lcd_print_char
  3350. ;
  3351. ; lcd_print_char('0' + units);
  3352. ;
  3353. L06F9: lda L0310
  3354. clc
  3355. adc #$30
  3356. jsr _lcd_print_char
  3357. ;
  3358. ; }
  3359. ;
  3360. jmp incsp2
  3361.  
  3362. .endproc
  3363.  
  3364. ; ---------------------------------------------------------------
  3365. ; void __near__ via_set_timer1 (unsigned int)
  3366. ; ---------------------------------------------------------------
  3367.  
  3368. .segment "CODE"
  3369.  
  3370. .proc _via_set_timer1: near
  3371.  
  3372. .segment "CODE"
  3373.  
  3374. ;
  3375. ; static void via_set_timer1(uint16_t count) {
  3376. ;
  3377. jsr pushax
  3378. ;
  3379. ; VIA_T1C_L = count & 0xFF;
  3380. ;
  3381. lda (sp)
  3382. sta $6004
  3383. ;
  3384. ; VIA_T1C_H = (count >> 8) & 0xFF;
  3385. ;
  3386. ldy #$01
  3387. lda (sp),y
  3388. sta $6005
  3389. ;
  3390. ; }
  3391. ;
  3392. jmp incsp2
  3393.  
  3394. .endproc
  3395.  
  3396. ; ---------------------------------------------------------------
  3397. ; void __near__ via_disable_interrupt (unsigned char)
  3398. ; ---------------------------------------------------------------
  3399.  
  3400. .segment "CODE"
  3401.  
  3402. .proc _via_disable_interrupt: near
  3403.  
  3404. .segment "CODE"
  3405.  
  3406. ;
  3407. ; static void via_disable_interrupt(uint8_t mask) {
  3408. ;
  3409. jsr pusha
  3410. ;
  3411. ; VIA_IER = mask & 0x7F; // Bit 7 = 0 (Clear)
  3412. ;
  3413. lda (sp)
  3414. and #$7F
  3415. sta $600E
  3416. ;
  3417. ; }
  3418. ;
  3419. jmp incsp1
  3420.  
  3421. .endproc
  3422.  
  3423. ; ---------------------------------------------------------------
  3424. ; void __near__ via_wait_frame (void)
  3425. ; ---------------------------------------------------------------
  3426.  
  3427. .segment "CODE"
  3428.  
  3429. .proc _via_wait_frame: near
  3430.  
  3431. .segment "CODE"
  3432.  
  3433. ;
  3434. ; while (!(VIA_IFR & 0x40));
  3435. ;
  3436. L0700: lda $600D
  3437. and #$40
  3438. beq L0700
  3439. ;
  3440. ; VIA_IFR = 0x40;
  3441. ;
  3442. lda #$40
  3443. sta $600D
  3444. ;
  3445. ; }
  3446. ;
  3447. rts
  3448.  
  3449. .endproc
  3450.  
  3451. ; ---------------------------------------------------------------
  3452. ; void __near__ via_init (void)
  3453. ; ---------------------------------------------------------------
  3454.  
  3455. .segment "CODE"
  3456.  
  3457. .proc _via_init: near
  3458.  
  3459. .segment "CODE"
  3460.  
  3461. ;
  3462. ; via_disable_interrupt(0x7F);
  3463. ;
  3464. lda #$7F
  3465. jsr _via_disable_interrupt
  3466. ;
  3467. ; VIA_ACR = 0x40;
  3468. ;
  3469. lda #$40
  3470. sta $600B
  3471. ;
  3472. ; via_set_timer1(VIA_T1_COUNT);
  3473. ;
  3474. ldx #$82
  3475. lda #$35
  3476. jsr _via_set_timer1
  3477. ;
  3478. ; asm("cli");
  3479. ;
  3480. cli
  3481. ;
  3482. ; }
  3483. ;
  3484. rts
  3485.  
  3486. .endproc
  3487.  
  3488. ; ---------------------------------------------------------------
  3489. ; void __near__ rotate_all (unsigned char, unsigned char, unsigned char)
  3490. ; ---------------------------------------------------------------
  3491.  
  3492. .segment "CODE"
  3493.  
  3494. .proc _rotate_all: near
  3495.  
  3496. .segment "BSS"
  3497.  
  3498. L04B1:
  3499. .res 2,$00
  3500. L04B2:
  3501. .res 2,$00
  3502. L04B3:
  3503. .res 2,$00
  3504. L04B4:
  3505. .res 2,$00
  3506. L04B5:
  3507. .res 2,$00
  3508. L04B6:
  3509. .res 2,$00
  3510. L04B7:
  3511. .res 2,$00
  3512. L04BE:
  3513. .res 2,$00
  3514. L04C6:
  3515. .res 2,$00
  3516. L04CD:
  3517. .res 2,$00
  3518. L04D5:
  3519. .res 2,$00
  3520. L04DC:
  3521. .res 2,$00
  3522.  
  3523. .segment "CODE"
  3524.  
  3525. ;
  3526. ; void rotate_all(unsigned char ax, unsigned char ay, unsigned char az) {
  3527. ;
  3528. jsr pusha
  3529. ;
  3530. ; register unsigned char i;
  3531. ;
  3532. lda regbank+5
  3533. jsr pusha
  3534. ;
  3535. ; int sin_x = ISIN(ax), cos_x = ICOS(ax);
  3536. ;
  3537. lda #<(_SIN_TABLE)
  3538. ldx #>(_SIN_TABLE)
  3539. ldy #$03
  3540. clc
  3541. adc (sp),y
  3542. bcc L04BC
  3543. inx
  3544. L04BC: ldy #$00
  3545. jsr ldaidx
  3546. ldx #$00
  3547. cmp #$80
  3548. bcc L04BD
  3549. dex
  3550. L04BD: sta L04B7
  3551. stx L04B7+1
  3552. ldy #$03
  3553. lda (sp),y
  3554. clc
  3555. adc #$40
  3556. clc
  3557. adc #<(_SIN_TABLE)
  3558. tay
  3559. lda #$00
  3560. adc #>(_SIN_TABLE)
  3561. tax
  3562. tya
  3563. ldy #$00
  3564. jsr ldaidx
  3565. ldx #$00
  3566. cmp #$80
  3567. bcc L04C5
  3568. dex
  3569. L04C5: sta L04BE
  3570. stx L04BE+1
  3571. ;
  3572. ; int sin_y = ISIN(ay), cos_y = ICOS(ay);
  3573. ;
  3574. lda #<(_SIN_TABLE)
  3575. ldx #>(_SIN_TABLE)
  3576. ldy #$02
  3577. clc
  3578. adc (sp),y
  3579. bcc L04CB
  3580. inx
  3581. L04CB: ldy #$00
  3582. jsr ldaidx
  3583. ldx #$00
  3584. cmp #$80
  3585. bcc L04CC
  3586. dex
  3587. L04CC: sta L04C6
  3588. stx L04C6+1
  3589. ldy #$02
  3590. lda (sp),y
  3591. clc
  3592. adc #$40
  3593. clc
  3594. adc #<(_SIN_TABLE)
  3595. tay
  3596. lda #$00
  3597. adc #>(_SIN_TABLE)
  3598. tax
  3599. tya
  3600. ldy #$00
  3601. jsr ldaidx
  3602. ldx #$00
  3603. cmp #$80
  3604. bcc L04D4
  3605. dex
  3606. L04D4: sta L04CD
  3607. stx L04CD+1
  3608. ;
  3609. ; int sin_z = ISIN(az), cos_z = ICOS(az);
  3610. ;
  3611. lda #<(_SIN_TABLE)
  3612. ldx #>(_SIN_TABLE)
  3613. iny
  3614. clc
  3615. adc (sp),y
  3616. bcc L04DA
  3617. inx
  3618. L04DA: dey
  3619. jsr ldaidx
  3620. ldx #$00
  3621. cmp #$80
  3622. bcc L04DB
  3623. dex
  3624. L04DB: sta L04D5
  3625. stx L04D5+1
  3626. iny
  3627. lda (sp),y
  3628. clc
  3629. adc #$40
  3630. clc
  3631. adc #<(_SIN_TABLE)
  3632. tay
  3633. lda #$00
  3634. adc #>(_SIN_TABLE)
  3635. tax
  3636. tya
  3637. ldy #$00
  3638. jsr ldaidx
  3639. ldx #$00
  3640. cmp #$80
  3641. bcc L04E3
  3642. dex
  3643. L04E3: sta L04DC
  3644. stx L04DC+1
  3645. ;
  3646. ; for (i = 0; i < 8; ++i) {
  3647. ;
  3648. stz regbank+5
  3649. L0701: lda regbank+5
  3650. cmp #$08
  3651. jcs L0707
  3652. ;
  3653. ; x = cvx[i];
  3654. ;
  3655. lda #<(_cvx)
  3656. ldx #>(_cvx)
  3657. clc
  3658. adc regbank+5
  3659. bcc L0702
  3660. inx
  3661. L0702: jsr ldaidx
  3662. ldx #$00
  3663. cmp #$80
  3664. bcc L04F0
  3665. dex
  3666. L04F0: sta L04B1
  3667. stx L04B1+1
  3668. ;
  3669. ; y = cvy[i];
  3670. ;
  3671. lda #<(_cvy)
  3672. ldx #>(_cvy)
  3673. clc
  3674. adc regbank+5
  3675. bcc L0703
  3676. inx
  3677. L0703: jsr ldaidx
  3678. ldx #$00
  3679. cmp #$80
  3680. bcc L04F5
  3681. dex
  3682. L04F5: sta L04B2
  3683. stx L04B2+1
  3684. ;
  3685. ; z = cvz[i];
  3686. ;
  3687. lda #<(_cvz)
  3688. ldx #>(_cvz)
  3689. clc
  3690. adc regbank+5
  3691. bcc L0704
  3692. inx
  3693. L0704: jsr ldaidx
  3694. ldx #$00
  3695. cmp #$80
  3696. bcc L04FA
  3697. dex
  3698. L04FA: sta L04B3
  3699. stx L04B3+1
  3700. ;
  3701. ; ty = (y * cos_x - z * sin_x) >> 7;
  3702. ;
  3703. lda L04B2
  3704. ldx L04B2+1
  3705. jsr pushax
  3706. lda L04BE
  3707. ldx L04BE+1
  3708. jsr tosmulax
  3709. jsr pushax
  3710. lda L04B3
  3711. ldx L04B3+1
  3712. jsr pushax
  3713. lda L04B7
  3714. ldx L04B7+1
  3715. jsr tosmulax
  3716. jsr tossubax
  3717. jsr asrax4
  3718. jsr asrax3
  3719. sta L04B5
  3720. stx L04B5+1
  3721. ;
  3722. ; tz = (y * sin_x + z * cos_x) >> 7;
  3723. ;
  3724. lda L04B2
  3725. ldx L04B2+1
  3726. jsr pushax
  3727. lda L04B7
  3728. ldx L04B7+1
  3729. jsr tosmulax
  3730. jsr pushax
  3731. lda L04B3
  3732. ldx L04B3+1
  3733. jsr pushax
  3734. lda L04BE
  3735. ldx L04BE+1
  3736. jsr tosmulax
  3737. jsr tosaddax
  3738. jsr asrax4
  3739. jsr asrax3
  3740. sta L04B6
  3741. stx L04B6+1
  3742. ;
  3743. ; y = ty;
  3744. ;
  3745. lda L04B5+1
  3746. sta L04B2+1
  3747. lda L04B5
  3748. sta L04B2
  3749. ;
  3750. ; z = tz;
  3751. ;
  3752. lda L04B6+1
  3753. sta L04B3+1
  3754. lda L04B6
  3755. sta L04B3
  3756. ;
  3757. ; tx = (x * cos_y + z * sin_y) >> 7;
  3758. ;
  3759. lda L04B1
  3760. ldx L04B1+1
  3761. jsr pushax
  3762. lda L04CD
  3763. ldx L04CD+1
  3764. jsr tosmulax
  3765. jsr pushax
  3766. lda L04B3
  3767. ldx L04B3+1
  3768. jsr pushax
  3769. lda L04C6
  3770. ldx L04C6+1
  3771. jsr tosmulax
  3772. jsr tosaddax
  3773. jsr asrax4
  3774. jsr asrax3
  3775. sta L04B4
  3776. stx L04B4+1
  3777. ;
  3778. ; tz = (-x * sin_y + z * cos_y) >> 7;
  3779. ;
  3780. lda L04B1
  3781. ldx L04B1+1
  3782. jsr negax
  3783. jsr pushax
  3784. lda L04C6
  3785. ldx L04C6+1
  3786. jsr tosmulax
  3787. jsr pushax
  3788. lda L04B3
  3789. ldx L04B3+1
  3790. jsr pushax
  3791. lda L04CD
  3792. ldx L04CD+1
  3793. jsr tosmulax
  3794. jsr tosaddax
  3795. jsr asrax4
  3796. jsr asrax3
  3797. sta L04B6
  3798. stx L04B6+1
  3799. ;
  3800. ; x = tx;
  3801. ;
  3802. lda L04B4+1
  3803. sta L04B1+1
  3804. lda L04B4
  3805. sta L04B1
  3806. ;
  3807. ; z = tz;
  3808. ;
  3809. lda L04B6+1
  3810. sta L04B3+1
  3811. lda L04B6
  3812. sta L04B3
  3813. ;
  3814. ; tx = (x * cos_z - y * sin_z) >> 7;
  3815. ;
  3816. lda L04B1
  3817. ldx L04B1+1
  3818. jsr pushax
  3819. lda L04DC
  3820. ldx L04DC+1
  3821. jsr tosmulax
  3822. jsr pushax
  3823. lda L04B2
  3824. ldx L04B2+1
  3825. jsr pushax
  3826. lda L04D5
  3827. ldx L04D5+1
  3828. jsr tosmulax
  3829. jsr tossubax
  3830. jsr asrax4
  3831. jsr asrax3
  3832. sta L04B4
  3833. stx L04B4+1
  3834. ;
  3835. ; ty = (x * sin_z + y * cos_z) >> 7;
  3836. ;
  3837. lda L04B1
  3838. ldx L04B1+1
  3839. jsr pushax
  3840. lda L04D5
  3841. ldx L04D5+1
  3842. jsr tosmulax
  3843. jsr pushax
  3844. lda L04B2
  3845. ldx L04B2+1
  3846. jsr pushax
  3847. lda L04DC
  3848. ldx L04DC+1
  3849. jsr tosmulax
  3850. jsr tosaddax
  3851. jsr asrax4
  3852. jsr asrax3
  3853. sta L04B5
  3854. stx L04B5+1
  3855. ;
  3856. ; vx[i] = tx;
  3857. ;
  3858. lda #<(_vx)
  3859. ldx #>(_vx)
  3860. clc
  3861. adc regbank+5
  3862. bcc L0517
  3863. inx
  3864. L0517: sta ptr1
  3865. stx ptr1+1
  3866. lda L04B4
  3867. ldy #$00
  3868. sta (ptr1)
  3869. ;
  3870. ; vy[i] = ty;
  3871. ;
  3872. lda #<(_vy)
  3873. ldx #>(_vy)
  3874. clc
  3875. adc regbank+5
  3876. bcc L051C
  3877. inx
  3878. L051C: sta ptr1
  3879. stx ptr1+1
  3880. lda L04B5
  3881. sta (ptr1)
  3882. ;
  3883. ; vz[i] = z;
  3884. ;
  3885. lda #<(_vz)
  3886. ldx #>(_vz)
  3887. clc
  3888. adc regbank+5
  3889. bcc L0521
  3890. inx
  3891. L0521: sta ptr1
  3892. stx ptr1+1
  3893. lda L04B3
  3894. sta (ptr1)
  3895. ;
  3896. ; for (i = 0; i < 8; ++i) {
  3897. ;
  3898. inc regbank+5
  3899. jmp L0701
  3900. ;
  3901. ; }
  3902. ;
  3903. L0707: lda (sp)
  3904. sta regbank+5
  3905. jmp incsp4
  3906.  
  3907. .endproc
  3908.  
  3909. ; ---------------------------------------------------------------
  3910. ; void __near__ project_all (void)
  3911. ; ---------------------------------------------------------------
  3912.  
  3913. .segment "CODE"
  3914.  
  3915. .proc _project_all: near
  3916.  
  3917. .segment "BSS"
  3918.  
  3919. L0525:
  3920. .res 1,$00
  3921. L0527:
  3922. .res 1,$00
  3923. L0529:
  3924. .res 2,$00
  3925. L052A:
  3926. .res 2,$00
  3927.  
  3928. .segment "CODE"
  3929.  
  3930. ;
  3931. ; register unsigned char i;
  3932. ;
  3933. lda regbank+5
  3934. jsr pusha
  3935. ;
  3936. ; const signed char distance = 80;
  3937. ;
  3938. lda #$50
  3939. sta L0525
  3940. ;
  3941. ; const signed char factor = 60;
  3942. ;
  3943. lda #$3C
  3944. sta L0527
  3945. ;
  3946. ; for (i = 0; i < 8; ++i) {
  3947. ;
  3948. stz regbank+5
  3949. L0708: lda regbank+5
  3950. cmp #$08
  3951. jcs L052C
  3952. ;
  3953. ; z_shifted = vz[i] + distance;
  3954. ;
  3955. lda #<(_vz)
  3956. ldx #>(_vz)
  3957. clc
  3958. adc regbank+5
  3959. bcc L0536
  3960. inx
  3961. L0536: ldy #$00
  3962. jsr ldaidx
  3963. sta ptr1
  3964. stx ptr1+1
  3965. ldx #$00
  3966. lda L0525
  3967. bpl L0537
  3968. dex
  3969. L0537: clc
  3970. adc ptr1
  3971. pha
  3972. txa
  3973. adc ptr1+1
  3974. tax
  3975. pla
  3976. sta L0529
  3977. stx L0529+1
  3978. ;
  3979. ; if (z_shifted < 10) z_shifted = 10;
  3980. ;
  3981. cmp #$0A
  3982. txa
  3983. sbc #$00
  3984. bvc L053A
  3985. eor #$80
  3986. L053A: bpl L0538
  3987. lda #$0A
  3988. sta L0529
  3989. stz L0529+1
  3990. ;
  3991. ; factor_precalc = (int)vx[i] * factor;
  3992. ;
  3993. L0538: lda #<(_vx)
  3994. ldx #>(_vx)
  3995. clc
  3996. adc regbank+5
  3997. bcc L0709
  3998. inx
  3999. L0709: jsr ldaidx
  4000. ldx #$00
  4001. cmp #$80
  4002. bcc L0541
  4003. dex
  4004. L0541: jsr pushax
  4005. ldx #$00
  4006. lda L0527
  4007. bpl L0542
  4008. dex
  4009. L0542: jsr tosmulax
  4010. sta L052A
  4011. stx L052A+1
  4012. ;
  4013. ; px[i] = (signed char)((factor_precalc / z_shifted) + (GPU_WIDTH / 2));
  4014. ;
  4015. lda #<(_px)
  4016. ldx #>(_px)
  4017. clc
  4018. adc regbank+5
  4019. bcc L0545
  4020. inx
  4021. L0545: jsr pushax
  4022. lda L052A
  4023. ldx L052A+1
  4024. jsr pushax
  4025. lda L0529
  4026. ldx L0529+1
  4027. jsr tosdivax
  4028. clc
  4029. adc #$32
  4030. cmp #$80
  4031. ldy #$00
  4032. jsr staspidx
  4033. ;
  4034. ; factor_precalc = (int)vy[i] * factor;
  4035. ;
  4036. lda #<(_vy)
  4037. ldx #>(_vy)
  4038. clc
  4039. adc regbank+5
  4040. bcc L054F
  4041. inx
  4042. L054F: ldy #$00
  4043. jsr ldaidx
  4044. ldx #$00
  4045. cmp #$80
  4046. bcc L0550
  4047. dex
  4048. L0550: jsr pushax
  4049. ldx #$00
  4050. lda L0527
  4051. bpl L0551
  4052. dex
  4053. L0551: jsr tosmulax
  4054. sta L052A
  4055. stx L052A+1
  4056. ;
  4057. ; py[i] = (signed char)((GPU_HEIGHT / 2) - (factor_precalc / z_shifted));
  4058. ;
  4059. lda #<(_py)
  4060. ldx #>(_py)
  4061. clc
  4062. adc regbank+5
  4063. bcc L0554
  4064. inx
  4065. L0554: jsr pushax
  4066. lda #$20
  4067. jsr pusha0
  4068. lda L052A
  4069. ldx L052A+1
  4070. jsr pushax
  4071. lda L0529
  4072. ldx L0529+1
  4073. jsr tosdivax
  4074. jsr tossubax
  4075. cmp #$80
  4076. ldy #$00
  4077. jsr staspidx
  4078. ;
  4079. ; for (i = 0; i < 8; ++i) {
  4080. ;
  4081. inc regbank+5
  4082. jmp L0708
  4083. ;
  4084. ; }
  4085. ;
  4086. L052C: lda (sp)
  4087. sta regbank+5
  4088. jmp incsp1
  4089.  
  4090. .endproc
  4091.  
  4092. ; ---------------------------------------------------------------
  4093. ; void __near__ init_graphics (void)
  4094. ; ---------------------------------------------------------------
  4095.  
  4096. .segment "CODE"
  4097.  
  4098. .proc _init_graphics: near
  4099.  
  4100. .segment "CODE"
  4101.  
  4102. ;
  4103. ; INIT_BUFFER();
  4104. ;
  4105. jsr _INIT_BUFFER
  4106. ;
  4107. ; lcd_init();
  4108. ;
  4109. jsr _lcd_init
  4110. ;
  4111. ; gpu_fill_screen(0x00);
  4112. ;
  4113. lda #$00
  4114. jmp _gpu_fill_screen
  4115.  
  4116. .endproc
  4117.  
  4118. ; ---------------------------------------------------------------
  4119. ; int __near__ main (void)
  4120. ; ---------------------------------------------------------------
  4121.  
  4122. .segment "CODE"
  4123.  
  4124. .proc _main: near
  4125.  
  4126. .segment "BSS"
  4127.  
  4128. L0561:
  4129. .res 1,$00
  4130. L0562:
  4131. .res 1,$00
  4132. L0563:
  4133. .res 1,$00
  4134. L0564:
  4135. .res 1,$00
  4136. L0565:
  4137. .res 1,$00
  4138. L0566:
  4139. .res 1,$00
  4140. L0567:
  4141. .res 1,$00
  4142. L0568:
  4143. .res 1,$00
  4144. L0569:
  4145. .res 1,$00
  4146. L056A:
  4147. .res 1,$00
  4148. L056B:
  4149. .res 1,$00
  4150. L056C:
  4151. .res 2,$00
  4152. L056D:
  4153. .res 2,$00
  4154. L056E:
  4155. .res 2,$00
  4156. L056F:
  4157. .res 2,$00
  4158. L0570:
  4159. .res 4,$00
  4160. L0571:
  4161. .res 3,$00
  4162. L0572:
  4163. .res 2,$00
  4164. L0573:
  4165. .res 1,$00
  4166. L0574:
  4167. .res 1,$00
  4168. L0575:
  4169. .res 1,$00
  4170. L0576:
  4171. .res 1,$00
  4172. L0577:
  4173. .res 1,$00
  4174. L0579:
  4175. .res 1,$00
  4176. L057B:
  4177. .res 1,$00
  4178. L057D:
  4179. .res 1,$00
  4180. L057F:
  4181. .res 2,$00
  4182.  
  4183. .segment "CODE"
  4184.  
  4185. ;
  4186. ; register unsigned char i;
  4187. ;
  4188. lda regbank+5
  4189. jsr pusha
  4190. ;
  4191. ; signed char clear_min_x = 0, clear_max_x = 0;
  4192. ;
  4193. stz L0577
  4194. stz L0579
  4195. ;
  4196. ; signed char clear_min_y = 0, clear_max_y = 0;
  4197. ;
  4198. stz L057B
  4199. stz L057D
  4200. ;
  4201. ; unsigned int seed = 0;
  4202. ;
  4203. stz L057F
  4204. stz L057F+1
  4205. ;
  4206. ; init_graphics();
  4207. ;
  4208. jsr _init_graphics
  4209. ;
  4210. ; via_init();
  4211. ;
  4212. jsr _via_init
  4213. ;
  4214. ; print_str("PRESS ANY KEY TO GENERATE SEED: ");
  4215. ;
  4216. lda #<(L0584)
  4217. ldx #>(L0584)
  4218. jsr _print_str
  4219. ;
  4220. ; while (bios_getchar_nb() == 0) {
  4221. ;
  4222. bra L0588
  4223. ;
  4224. ; seed++;
  4225. ;
  4226. L0586: lda L057F
  4227. ldx L057F+1
  4228. ina
  4229. bne L058B
  4230. inx
  4231. L058B: sta L057F
  4232. stx L057F+1
  4233. ;
  4234. ; while (bios_getchar_nb() == 0) {
  4235. ;
  4236. L0588: jsr _MONGETCHAR_NB
  4237. cmp #$00
  4238. beq L0586
  4239. ;
  4240. ; srand(seed);
  4241. ;
  4242. lda L057F
  4243. ldx L057F+1
  4244. jsr _srand
  4245. ;
  4246. ; gpu_fill_screen(0x00);
  4247. ;
  4248. lda #$00
  4249. jsr _gpu_fill_screen
  4250. ;
  4251. ; lcd_print("Rotating Cube");
  4252. ;
  4253. lda #<(L0591)
  4254. ldx #>(L0591)
  4255. jsr _lcd_print
  4256. ;
  4257. ; ang_x = (unsigned char)(rand());
  4258. ;
  4259. jsr _rand
  4260. sta L0561
  4261. ;
  4262. ; ang_y = (unsigned char)(rand());
  4263. ;
  4264. jsr _rand
  4265. sta L0562
  4266. ;
  4267. ; ang_z = (unsigned char)(rand());
  4268. ;
  4269. jsr _rand
  4270. sta L0563
  4271. ;
  4272. ; speed_x = (char)((rand() % 8) + 1);
  4273. ;
  4274. jsr _rand
  4275. jsr pushax
  4276. ldx #$00
  4277. lda #$08
  4278. jsr tosmoda0
  4279. ina
  4280. sta L0564
  4281. ;
  4282. ; if (rand() & 1) speed_x = -speed_x;
  4283. ;
  4284. jsr _rand
  4285. and #$01
  4286. beq L05A1
  4287. lda L0564
  4288. eor #$FF
  4289. clc
  4290. adc #$01
  4291. sta L0564
  4292. ;
  4293. ; speed_y = (char)((rand() % 8) + 1);
  4294. ;
  4295. L05A1: jsr _rand
  4296. jsr pushax
  4297. ldx #$00
  4298. lda #$08
  4299. jsr tosmoda0
  4300. ina
  4301. sta L0565
  4302. ;
  4303. ; if (rand() & 1) speed_y = -speed_y;
  4304. ;
  4305. jsr _rand
  4306. and #$01
  4307. beq L05AA
  4308. lda L0565
  4309. eor #$FF
  4310. clc
  4311. adc #$01
  4312. sta L0565
  4313. ;
  4314. ; speed_z = (char)((rand() % 8) + 1);
  4315. ;
  4316. L05AA: jsr _rand
  4317. jsr pushax
  4318. ldx #$00
  4319. lda #$08
  4320. jsr tosmoda0
  4321. ina
  4322. sta L0566
  4323. ;
  4324. ; if (rand() & 1) speed_z = -speed_z;
  4325. ;
  4326. jsr _rand
  4327. and #$01
  4328. beq L05B7
  4329. lda L0566
  4330. eor #$FF
  4331. clc
  4332. adc #$01
  4333. sta L0566
  4334. ;
  4335. ; if (clear_max_x >= clear_min_x && clear_max_y >= clear_min_y) {
  4336. ;
  4337. L05B7: ldx #$00
  4338. lda L0579
  4339. bpl L05BD
  4340. dex
  4341. L05BD: jsr pushax
  4342. ldx #$00
  4343. lda L0577
  4344. bpl L05BE
  4345. dex
  4346. L05BE: jsr tosicmp
  4347. bmi L070C
  4348. ldx #$00
  4349. lda L057D
  4350. bpl L05C0
  4351. dex
  4352. L05C0: jsr pushax
  4353. ldx #$00
  4354. lda L057B
  4355. bpl L05C1
  4356. dex
  4357. L05C1: jsr tosicmp
  4358. bmi L070C
  4359. ;
  4360. ; gpu_draw_rect(clear_min_x, clear_min_y,
  4361. ;
  4362. jsr decsp4
  4363. lda L0577
  4364. ldy #$03
  4365. sta (sp),y
  4366. lda L057B
  4367. dey
  4368. sta (sp),y
  4369. ;
  4370. ; clear_max_x - clear_min_x + 1,
  4371. ;
  4372. ldx #$00
  4373. lda L0579
  4374. bpl L05C7
  4375. dex
  4376. L05C7: jsr pushax
  4377. ldx #$00
  4378. lda L0577
  4379. bpl L05C8
  4380. dex
  4381. L05C8: jsr tossubax
  4382. ina
  4383. cmp #$80
  4384. ldy #$01
  4385. sta (sp),y
  4386. ;
  4387. ; clear_max_y - clear_min_y + 1,
  4388. ;
  4389. ldx #$00
  4390. lda L057D
  4391. bpl L05CC
  4392. dex
  4393. L05CC: jsr pushax
  4394. ldx #$00
  4395. lda L057B
  4396. bpl L05CD
  4397. dex
  4398. L05CD: jsr tossubax
  4399. ina
  4400. cmp #$80
  4401. sta (sp)
  4402. ;
  4403. ; black_color);
  4404. ;
  4405. lda _black_color
  4406. jsr _gpu_draw_rect
  4407. ;
  4408. ; ang_x += speed_x;
  4409. ;
  4410. L070C: lda L0564
  4411. clc
  4412. adc L0561
  4413. sta L0561
  4414. ;
  4415. ; ang_y += speed_y;
  4416. ;
  4417. lda L0565
  4418. clc
  4419. adc L0562
  4420. sta L0562
  4421. ;
  4422. ; ang_z += speed_z;
  4423. ;
  4424. lda L0566
  4425. clc
  4426. adc L0563
  4427. sta L0563
  4428. ;
  4429. ; rotate_all(ang_x, ang_y, ang_z);
  4430. ;
  4431. jsr decsp2
  4432. lda L0561
  4433. ldy #$01
  4434. sta (sp),y
  4435. lda L0562
  4436. sta (sp)
  4437. lda L0563
  4438. jsr _rotate_all
  4439. ;
  4440. ; project_all();
  4441. ;
  4442. jsr _project_all
  4443. ;
  4444. ; min_x = 127;
  4445. ;
  4446. lda #$7F
  4447. sta L0573
  4448. ;
  4449. ; max_x = -128;
  4450. ;
  4451. ina
  4452. sta L0574
  4453. ;
  4454. ; min_y = 127;
  4455. ;
  4456. dea
  4457. sta L0575
  4458. ;
  4459. ; max_y = -128;
  4460. ;
  4461. ina
  4462. sta L0576
  4463. ;
  4464. ; for (i = 0; i < 8; ++i) {
  4465. ;
  4466. stz regbank+5
  4467. L070D: lda regbank+5
  4468. cmp #$08
  4469. jcs L070E
  4470. ;
  4471. ; if (px[i] < min_x) min_x = px[i];
  4472. ;
  4473. lda #<(_px)
  4474. ldx #>(_px)
  4475. clc
  4476. adc regbank+5
  4477. bcc L05EF
  4478. inx
  4479. L05EF: ldy #$00
  4480. jsr ldaidx
  4481. jsr pushax
  4482. ldx #$00
  4483. lda L0573
  4484. bpl L05F0
  4485. dex
  4486. L05F0: jsr tosicmp
  4487. bpl L05EC
  4488. lda #<(_px)
  4489. ldx #>(_px)
  4490. clc
  4491. adc regbank+5
  4492. bcc L05F4
  4493. inx
  4494. L05F4: ldy #$00
  4495. jsr ldaidx
  4496. sta L0573
  4497. ;
  4498. ; if (px[i] > max_x) max_x = px[i];
  4499. ;
  4500. L05EC: lda #<(_px)
  4501. ldx #>(_px)
  4502. clc
  4503. adc regbank+5
  4504. bcc L05F8
  4505. inx
  4506. L05F8: ldy #$00
  4507. jsr ldaidx
  4508. jsr pushax
  4509. ldx #$00
  4510. lda L0574
  4511. bpl L05F9
  4512. dex
  4513. L05F9: jsr tosicmp
  4514. bmi L05F5
  4515. beq L05F5
  4516. lda #<(_px)
  4517. ldx #>(_px)
  4518. clc
  4519. adc regbank+5
  4520. bcc L05FD
  4521. inx
  4522. L05FD: ldy #$00
  4523. jsr ldaidx
  4524. sta L0574
  4525. ;
  4526. ; if (py[i] < min_y) min_y = py[i];
  4527. ;
  4528. L05F5: lda #<(_py)
  4529. ldx #>(_py)
  4530. clc
  4531. adc regbank+5
  4532. bcc L0601
  4533. inx
  4534. L0601: ldy #$00
  4535. jsr ldaidx
  4536. jsr pushax
  4537. ldx #$00
  4538. lda L0575
  4539. bpl L0602
  4540. dex
  4541. L0602: jsr tosicmp
  4542. bpl L05FE
  4543. lda #<(_py)
  4544. ldx #>(_py)
  4545. clc
  4546. adc regbank+5
  4547. bcc L0606
  4548. inx
  4549. L0606: ldy #$00
  4550. jsr ldaidx
  4551. sta L0575
  4552. ;
  4553. ; if (py[i] > max_y) max_y = py[i];
  4554. ;
  4555. L05FE: lda #<(_py)
  4556. ldx #>(_py)
  4557. clc
  4558. adc regbank+5
  4559. bcc L060A
  4560. inx
  4561. L060A: ldy #$00
  4562. jsr ldaidx
  4563. jsr pushax
  4564. ldx #$00
  4565. lda L0576
  4566. bpl L060B
  4567. dex
  4568. L060B: jsr tosicmp
  4569. bmi L05E6
  4570. beq L05E6
  4571. lda #<(_py)
  4572. ldx #>(_py)
  4573. clc
  4574. adc regbank+5
  4575. bcc L060F
  4576. inx
  4577. L060F: ldy #$00
  4578. jsr ldaidx
  4579. sta L0576
  4580. ;
  4581. ; for (i = 0; i < 8; ++i) {
  4582. ;
  4583. L05E6: inc regbank+5
  4584. jmp L070D
  4585. ;
  4586. ; if (min_x < 0) min_x = 0;
  4587. ;
  4588. L070E: lda L0573
  4589. asl a
  4590. bcc L070F
  4591. stz L0573
  4592. ;
  4593. ; if (max_x >= GPU_WIDTH) max_x = GPU_WIDTH - 1;
  4594. ;
  4595. L070F: lda L0574
  4596. sec
  4597. sbc #$64
  4598. bvs L0618
  4599. eor #$80
  4600. L0618: bpl L0710
  4601. lda #$63
  4602. sta L0574
  4603. ;
  4604. ; if (min_y < 0) min_y = 0;
  4605. ;
  4606. L0710: lda L0575
  4607. asl a
  4608. bcc L0711
  4609. stz L0575
  4610. ;
  4611. ; if (max_y >= GPU_HEIGHT) max_y = GPU_HEIGHT - 1;
  4612. ;
  4613. L0711: lda L0576
  4614. sec
  4615. sbc #$40
  4616. bvs L0623
  4617. eor #$80
  4618. L0623: bpl L0712
  4619. lda #$3F
  4620. sta L0576
  4621. ;
  4622. ; clear_min_x = min_x;
  4623. ;
  4624. L0712: lda L0573
  4625. sta L0577
  4626. ;
  4627. ; clear_max_x = max_x;
  4628. ;
  4629. lda L0574
  4630. sta L0579
  4631. ;
  4632. ; clear_min_y = min_y;
  4633. ;
  4634. lda L0575
  4635. sta L057B
  4636. ;
  4637. ; clear_max_y = max_y;
  4638. ;
  4639. lda L0576
  4640. sta L057D
  4641. ;
  4642. ; count = 0;
  4643. ;
  4644. stz L056B
  4645. ;
  4646. ; for (i = 0; i < 12; ++i) {
  4647. ;
  4648. stz regbank+5
  4649. L0713: lda regbank+5
  4650. cmp #$0C
  4651. jcs L0714
  4652. ;
  4653. ; p1 = faces[i][0];
  4654. ;
  4655. ldx #$00
  4656. lda regbank+5
  4657. jsr mulax3
  4658. sta ptr1
  4659. txa
  4660. clc
  4661. adc #>(_faces)
  4662. sta ptr1+1
  4663. ldy #<(_faces)
  4664. lda (ptr1),y
  4665. sta L0568
  4666. ;
  4667. ; p2 = faces[i][1];
  4668. ;
  4669. ldx #$00
  4670. lda regbank+5
  4671. jsr mulax3
  4672. clc
  4673. adc #<(_faces)
  4674. sta ptr1
  4675. txa
  4676. adc #>(_faces)
  4677. sta ptr1+1
  4678. ldy #$01
  4679. lda (ptr1),y
  4680. sta L0569
  4681. ;
  4682. ; p3 = faces[i][2];
  4683. ;
  4684. ldx #$00
  4685. lda regbank+5
  4686. jsr mulax3
  4687. clc
  4688. adc #<(_faces)
  4689. sta ptr1
  4690. txa
  4691. adc #>(_faces)
  4692. sta ptr1+1
  4693. iny
  4694. lda (ptr1),y
  4695. sta L056A
  4696. ;
  4697. ; v1x = px[p2] - px[p1];
  4698. ;
  4699. lda #<(_px)
  4700. ldx #>(_px)
  4701. clc
  4702. adc L0569
  4703. bcc L064B
  4704. inx
  4705. L064B: ldy #$00
  4706. jsr ldaidx
  4707. jsr pushax
  4708. lda #<(_px)
  4709. ldx #>(_px)
  4710. clc
  4711. adc L0568
  4712. bcc L064D
  4713. inx
  4714. L064D: ldy #$00
  4715. jsr ldaidx
  4716. jsr tossubax
  4717. sta L056C
  4718. stx L056C+1
  4719. ;
  4720. ; v1y = py[p2] - py[p1];
  4721. ;
  4722. lda #<(_py)
  4723. ldx #>(_py)
  4724. clc
  4725. adc L0569
  4726. bcc L0651
  4727. inx
  4728. L0651: ldy #$00
  4729. jsr ldaidx
  4730. jsr pushax
  4731. lda #<(_py)
  4732. ldx #>(_py)
  4733. clc
  4734. adc L0568
  4735. bcc L0653
  4736. inx
  4737. L0653: ldy #$00
  4738. jsr ldaidx
  4739. jsr tossubax
  4740. sta L056D
  4741. stx L056D+1
  4742. ;
  4743. ; v2x = px[p3] - px[p1];
  4744. ;
  4745. lda #<(_px)
  4746. ldx #>(_px)
  4747. clc
  4748. adc L056A
  4749. bcc L0657
  4750. inx
  4751. L0657: ldy #$00
  4752. jsr ldaidx
  4753. jsr pushax
  4754. lda #<(_px)
  4755. ldx #>(_px)
  4756. clc
  4757. adc L0568
  4758. bcc L0659
  4759. inx
  4760. L0659: ldy #$00
  4761. jsr ldaidx
  4762. jsr tossubax
  4763. sta L056E
  4764. stx L056E+1
  4765. ;
  4766. ; v2y = py[p3] - py[p1];
  4767. ;
  4768. lda #<(_py)
  4769. ldx #>(_py)
  4770. clc
  4771. adc L056A
  4772. bcc L065D
  4773. inx
  4774. L065D: ldy #$00
  4775. jsr ldaidx
  4776. jsr pushax
  4777. lda #<(_py)
  4778. ldx #>(_py)
  4779. clc
  4780. adc L0568
  4781. bcc L065F
  4782. inx
  4783. L065F: ldy #$00
  4784. jsr ldaidx
  4785. jsr tossubax
  4786. sta L056F
  4787. stx L056F+1
  4788. ;
  4789. ; cross = (long)v1x * v2y - (long)v1y * v2x;
  4790. ;
  4791. lda L056C
  4792. ldx L056C+1
  4793. jsr axlong
  4794. jsr pusheax
  4795. lda L056F
  4796. ldx L056F+1
  4797. jsr axlong
  4798. jsr tosmuleax
  4799. jsr pusheax
  4800. lda L056D
  4801. ldx L056D+1
  4802. jsr axlong
  4803. jsr pusheax
  4804. lda L056E
  4805. ldx L056E+1
  4806. jsr axlong
  4807. jsr tosmuleax
  4808. jsr tossubeax
  4809. sta L0570
  4810. stx L0570+1
  4811. ldy sreg
  4812. sty L0570+2
  4813. ldy sreg+1
  4814. sty L0570+3
  4815. ;
  4816. ; if (cross >= 0) {
  4817. ;
  4818. lda L0570+3
  4819. sta sreg+1
  4820. lda L0570+2
  4821. sta sreg
  4822. lda sreg+1
  4823. bmi L0636
  4824. ;
  4825. ; visible_faces[count].id = i;
  4826. ;
  4827. ldx #$00
  4828. lda L056B
  4829. jsr mulax3
  4830. clc
  4831. adc #<(_visible_faces)
  4832. sta ptr1
  4833. txa
  4834. adc #>(_visible_faces)
  4835. sta ptr1+1
  4836. lda regbank+5
  4837. sta (ptr1)
  4838. ;
  4839. ; visible_faces[count].z_depth = vz[p1] + vz[p2] + vz[p3];
  4840. ;
  4841. ldx #$00
  4842. lda L056B
  4843. jsr mulax3
  4844. clc
  4845. adc #<(_visible_faces)
  4846. tay
  4847. txa
  4848. adc #>(_visible_faces)
  4849. tax
  4850. tya
  4851. jsr pushax
  4852. lda #<(_vz)
  4853. ldx #>(_vz)
  4854. clc
  4855. adc L0568
  4856. bcc L066B
  4857. inx
  4858. L066B: ldy #$00
  4859. jsr ldaidx
  4860. jsr pushax
  4861. lda #<(_vz)
  4862. ldx #>(_vz)
  4863. clc
  4864. adc L0569
  4865. bcc L066D
  4866. inx
  4867. L066D: ldy #$00
  4868. jsr ldaidx
  4869. jsr tosaddax
  4870. jsr pushax
  4871. lda #<(_vz)
  4872. ldx #>(_vz)
  4873. clc
  4874. adc L056A
  4875. bcc L066F
  4876. inx
  4877. L066F: ldy #$00
  4878. jsr ldaidx
  4879. jsr tosaddax
  4880. ldy #$01
  4881. jsr staxspidx
  4882. ;
  4883. ; count++;
  4884. ;
  4885. inc L056B
  4886. ;
  4887. ; for (i = 0; i < 12; ++i) {
  4888. ;
  4889. L0636: inc regbank+5
  4890. jmp L0713
  4891. ;
  4892. ; for (i = 1; i < count; ++i) {
  4893. ;
  4894. L0714: lda #$01
  4895. sta regbank+5
  4896. ldx #$00
  4897. L0715: lda regbank+5
  4898. cmp L056B
  4899. jcs L071A
  4900. ;
  4901. ; temp_face = visible_faces[i];
  4902. ;
  4903. lda #<(L0571)
  4904. ldx #>(L0571)
  4905. jsr pushax
  4906. ldx #$00
  4907. lda regbank+5
  4908. jsr mulax3
  4909. clc
  4910. adc #<(_visible_faces)
  4911. tay
  4912. txa
  4913. adc #>(_visible_faces)
  4914. tax
  4915. tya
  4916. jsr pushax
  4917. ldx #$00
  4918. lda #$03
  4919. jsr _memcpy
  4920. ;
  4921. ; j_sort = i - 1;
  4922. ;
  4923. ldx #$00
  4924. lda regbank+5
  4925. ;
  4926. ; while (j_sort >= 0 && visible_faces[j_sort].z_depth < temp_face.z_depth) {
  4927. ;
  4928. bra L071E
  4929. ;
  4930. ; visible_faces[j_sort + 1] = visible_faces[j_sort];
  4931. ;
  4932. L067F: lda L0572
  4933. ldx L0572+1
  4934. ina
  4935. bne L0688
  4936. inx
  4937. L0688: jsr mulax3
  4938. clc
  4939. adc #<(_visible_faces)
  4940. tay
  4941. txa
  4942. adc #>(_visible_faces)
  4943. tax
  4944. tya
  4945. jsr pushax
  4946. lda L0572
  4947. ldx L0572+1
  4948. jsr mulax3
  4949. clc
  4950. adc #<(_visible_faces)
  4951. tay
  4952. txa
  4953. adc #>(_visible_faces)
  4954. tax
  4955. tya
  4956. jsr pushax
  4957. ldx #$00
  4958. lda #$03
  4959. jsr _memcpy
  4960. ;
  4961. ; j_sort--;
  4962. ;
  4963. lda L0572
  4964. ldx L0572+1
  4965. L071E: sec
  4966. sbc #$01
  4967. bcs L068C
  4968. dex
  4969. L068C: sta L0572
  4970. stx L0572+1
  4971. ;
  4972. ; while (j_sort >= 0 && visible_faces[j_sort].z_depth < temp_face.z_depth) {
  4973. ;
  4974. ldx L0572+1
  4975. bmi L070B
  4976. lda L0572
  4977. ldx L0572+1
  4978. jsr mulax3
  4979. clc
  4980. adc #<(_visible_faces)
  4981. sta ptr1
  4982. txa
  4983. adc #>(_visible_faces)
  4984. sta ptr1+1
  4985. ldy #$02
  4986. lda (ptr1),y
  4987. tax
  4988. dey
  4989. lda (ptr1),y
  4990. cmp L0571+1
  4991. txa
  4992. sbc L0571+1+1
  4993. bvc L070A
  4994. eor #$80
  4995. L070A: bmi L067F
  4996. ;
  4997. ; visible_faces[j_sort + 1] = temp_face;
  4998. ;
  4999. L070B: lda L0572
  5000. ldx L0572+1
  5001. ina
  5002. bne L068F
  5003. inx
  5004. L068F: jsr mulax3
  5005. clc
  5006. adc #<(_visible_faces)
  5007. tay
  5008. txa
  5009. adc #>(_visible_faces)
  5010. tax
  5011. tya
  5012. jsr pushax
  5013. lda #<(L0571)
  5014. ldx #>(L0571)
  5015. jsr pushax
  5016. ldx #$00
  5017. lda #$03
  5018. jsr _memcpy
  5019. ;
  5020. ; for (i = 1; i < count; ++i) {
  5021. ;
  5022. ldx #$00
  5023. inc regbank+5
  5024. jmp L0715
  5025. ;
  5026. ; for (i = 0; i < count; ++i) {
  5027. ;
  5028. L071A: stz regbank+5
  5029. L0718: lda regbank+5
  5030. cmp L056B
  5031. jcs L0692
  5032. ;
  5033. ; f = visible_faces[i].id;
  5034. ;
  5035. jsr mulax3
  5036. sta ptr1
  5037. txa
  5038. clc
  5039. adc #>(_visible_faces)
  5040. sta ptr1+1
  5041. ldy #<(_visible_faces)
  5042. lda (ptr1),y
  5043. sta L0567
  5044. ;
  5045. ; p1 = faces[f][0];
  5046. ;
  5047. ldx #$00
  5048. lda L0567
  5049. jsr mulax3
  5050. sta ptr1
  5051. txa
  5052. clc
  5053. adc #>(_faces)
  5054. sta ptr1+1
  5055. ldy #<(_faces)
  5056. lda (ptr1),y
  5057. sta L0568
  5058. ;
  5059. ; p2 = faces[f][1];
  5060. ;
  5061. ldx #$00
  5062. lda L0567
  5063. jsr mulax3
  5064. clc
  5065. adc #<(_faces)
  5066. sta ptr1
  5067. txa
  5068. adc #>(_faces)
  5069. sta ptr1+1
  5070. ldy #$01
  5071. lda (ptr1),y
  5072. sta L0569
  5073. ;
  5074. ; p3 = faces[f][2];
  5075. ;
  5076. ldx #$00
  5077. lda L0567
  5078. jsr mulax3
  5079. clc
  5080. adc #<(_faces)
  5081. sta ptr1
  5082. txa
  5083. adc #>(_faces)
  5084. sta ptr1+1
  5085. iny
  5086. lda (ptr1),y
  5087. sta L056A
  5088. ;
  5089. ; px[p1], py[p1],
  5090. ;
  5091. jsr decsp7
  5092. lda #<(_px)
  5093. ldx #>(_px)
  5094. clc
  5095. adc L0568
  5096. bcc L06AB
  5097. inx
  5098. L06AB: ldy #$00
  5099. jsr ldaidx
  5100. ldy #$06
  5101. sta (sp),y
  5102. lda #<(_py)
  5103. ldx #>(_py)
  5104. clc
  5105. adc L0568
  5106. bcc L06AE
  5107. inx
  5108. L06AE: ldy #$00
  5109. jsr ldaidx
  5110. ldy #$05
  5111. sta (sp),y
  5112. ;
  5113. ; px[p2], py[p2],
  5114. ;
  5115. lda #<(_px)
  5116. ldx #>(_px)
  5117. clc
  5118. adc L0569
  5119. bcc L06B1
  5120. inx
  5121. L06B1: ldy #$00
  5122. jsr ldaidx
  5123. ldy #$04
  5124. sta (sp),y
  5125. lda #<(_py)
  5126. ldx #>(_py)
  5127. clc
  5128. adc L0569
  5129. bcc L06B4
  5130. inx
  5131. L06B4: ldy #$00
  5132. jsr ldaidx
  5133. ldy #$03
  5134. sta (sp),y
  5135. ;
  5136. ; px[p3], py[p3],
  5137. ;
  5138. lda #<(_px)
  5139. ldx #>(_px)
  5140. clc
  5141. adc L056A
  5142. bcc L06B7
  5143. inx
  5144. L06B7: ldy #$00
  5145. jsr ldaidx
  5146. ldy #$02
  5147. sta (sp),y
  5148. lda #<(_py)
  5149. ldx #>(_py)
  5150. clc
  5151. adc L056A
  5152. bcc L06BA
  5153. inx
  5154. L06BA: ldy #$00
  5155. jsr ldaidx
  5156. iny
  5157. sta (sp),y
  5158. ;
  5159. ; face_colors[f],
  5160. ;
  5161. ldy L0567
  5162. lda _face_colors,y
  5163. sta (sp)
  5164. ;
  5165. ; );
  5166. ;
  5167. lda #$01
  5168. jsr _gpu_draw_tri
  5169. ;
  5170. ; for (i = 0; i < count; ++i) {
  5171. ;
  5172. ldx #$00
  5173. inc regbank+5
  5174. jmp L0718
  5175. ;
  5176. ; via_wait_frame();
  5177. ;
  5178. L0692: jsr _via_wait_frame
  5179. ;
  5180. ; while (1) {
  5181. ;
  5182. jmp L05B7
  5183.  
  5184. .endproc
  5185.  
  5186.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment