Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
23 May, 2013, 02:34:06 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Mad DJNZ Hacks -  (Read 910 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
thepenguin77
z80 Assembly Master
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 01:15:58
Date Registered: 14 December, 2009, 04:21:52
Location: Purdue
Posts: 1484


Topic starter
Total Post Ratings: +778

View Profile
« on: 21 October, 2011, 23:53:11 »
+2

I was looking through starfox when I saw some code that used DJNZ in an unconventional way, this made me think about how useful it is, so here are some things I just thought of.

On this first one, you're going to say, "well duh," but I bet you don't do it.

Let's say you want to see if A==1:

1
2
3
dec a
jr nz, AWasnt1

You could replace it with this for only 1 extra t-state:

1
2
3
ld b, a
djnz AWasnt1

One benefit of this is that you don't destroy A. Now before you start complaining about that 1 t-state, just remember, if you manage to put your result into B rather than A, this routine becomes 3 t-states faster.


Here is another common code structure that I run into a lot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ld a, (hl)
dec a
jr nz, not1
...
jr final
not1:
dec a
jr nz, not2
...
jr final
not2:
dec a
jr nz, not3
...
jr final
not3:
dec a
jr nz, not4
...
jr final
not4:
...
final:

Why not replace it with this, which is both faster and smaller (you don't need the jumps if you can leave b at 0):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ld b, (hl)
djnz not1
...
not1:
djnz not2
...
not2:
djnz not3
...
not3:
djnz not4
...
not4:
djnz not5
...
not5:

final:


Finally, this one is a bit more of a stretch, but you can use B as a flag byte, take for instance this byte plotter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;######################################
;plot a byte
;a = byte
;b = inverse 1 = yes, 0 = no
;de = xy

plotAByte:
ld c, d
ld d, 0
ld h, d
ld l, e
add hl, de
add hl, de
add hl, hl
add hl, hl
srl c
srl c
srl c
ld e, c
add hl, de
ld de, plotSScreen
add hl, de

djnz inversing

or (hl)
ld (hl), a
ret

inversing:
cpl
and (hl)
ld (hl), a
ret


Also, while it's not a new idea today, I have used DJNZ in weird ways before, I typically do it when unpacking bytes from storage. This routine is from zStart and pulls a name out of storage from 6 bytes to 8 bytes. I use B as a bit counter.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pop hl
ld ix, op1+1
ld bc, 8*256+6
ld d, 8
xor a
unpackNameLoop:
rr (hl)
rra
djnz notNextUnpackByte
inc hl
ld b, 8
notNextUnpackByte:
dec c
jr nz, unpackNameLoop
ld c, 6
rra
rra
ld (ix), a
inc ix
xor a
dec d
jr nz, unpackNameLoop
« Last Edit: 22 October, 2011, 00:05:58 by thepenguin77 » Logged

zStart v1.3.011 4-29-2013  zStart fully works on 83+BE's (except custom font)
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112
boot2490
LV7 Elite (Next: 700)
*******
Offline Offline

Gender: Male
Last Login: 28 April, 2013, 05:54:45
Date Registered: 27 February, 2011, 07:39:51
Location: Pittsburgh, PA
Posts: 605


Total Post Ratings: +18

View Profile WWW
« Reply #1 on: 22 October, 2011, 00:07:29 »
0

What
seems cool though
Logged

I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler for Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.
ralphdspam
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 14 May, 2013, 09:10:11
Date Registered: 01 February, 2011, 07:58:40
Location: California, USA
Posts: 841


Total Post Ratings: +36

View Profile
« Reply #2 on: 26 October, 2011, 22:48:06 »
0

Why not replace it with this, which is both faster and smaller (you don't need the jumps if you can leave b at 0):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ld b, (hl)
djnz not1
...
not1:
djnz not2
...
not2:
djnz not3
...
not3:
djnz not4
...
not4:
djnz not5
...
not5:

final:
Wow!  That's great stuff!  Cheesy
Plus you can keep your original value unchanged in A.  
« Last Edit: 26 October, 2011, 22:48:16 by ralphdspam » Logged

ld a, 0
ld a, a
Xeda112358
Xombie. I am it.
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Online Online

Last Login: Today at 02:33:47
Date Registered: 31 October, 2010, 08:46:36
Location: Land of Little Cubes and Tea, NY
Posts: 3759


Total Post Ratings: +609

View Profile
« Reply #3 on: 30 October, 2011, 01:43:36 »
0

I use djnz to jump forward very often, actually, and it is a trick I figured out and exploited when I created my first asm library all the way up to BatLib :) I even made a note of it in my opcode chart:
Quote from: Zeda's Opcode Chart
DJNZ * decrements B. If B is   not 0, it pretends to be a jr. If B is 0, the code continues. This is mostly used for loops because it uses only 2 bytes, so * is usually negative. Because of this, people seem to forget that you can jump forward with this. :P   

EDIT: and I use it for things like selecting a sprite method to draw with, rectangle method, pixel plotting method, et cetera.
« Last Edit: 30 October, 2011, 01:45:38 by Xeda112358 » Logged



Grammer Download (2.29.04.12)
Latest update (possibly incomplete)
My pastebin
Spoiler for FileSyst:
FileSyst is an application that provides a folder and filesystem for the TI-83+/84+ calculators. It is designed to be easy to access and use in BASIC, and it can be used to access game files and save data, or to create a command prompt, among other things:

Spoiler for Graphiti:
This is a graph explorer for graph theory. It will require lots of work to finish. Currently you can:
Add/delete vertices
Add edges (direction not shown, but they are directed)
Arrange vertices in a circle (in the future, you will be able to define levels of rings and the number of nodes in each)
Create complete graphs quickly

Plans:
Add adjacency matrix viewer
Deleting edges
Multiple graphs support
Arrows for directed graphs
Planarity testing
Matrix operations
Weighted edges
Chromatic polynomials
Chromatic numbers

Spoiler for Stats:

Samocal             [o---------]
Virtual Processor   [o---------]
EnG                 [oo--------]
Grammer             [ooo-------]
AsmComp             [ooo-------]
Partex              [oooo------]
BatLib              [oooooooo--]
Grammer82           [----------]
Grammer68000        [----------]


Pseudonyms:  Zeda, Xeda, Thunderbolt
Languages:   English, français
Programming: z80 Assmebly
             Grammer
             TI-BASIC (83/84/+/SE, 89/89t/92)
Known For:   -Creator of the Grammer programming language
              (Winning program of zContest2011)
             -BatLib- One of the most feature packed libraries for BASIC programmers available
              with over 100 functions and a simple programming language
             -Learning to program z80 in hexadecimal before using an assembler (no computer was
              available!)
╔═╦╗░╠═╬╣▒║ ║║▓╚═╩╝█


calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 21:27:24
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2735


Total Post Ratings: +373

View Profile
« Reply #4 on: 18 January, 2012, 05:34:01 »
+2

Another DJNZ hack is that you can use DJNZ $+2 to decrease B without affecting any flags. It's 4-9 cycles slower than normal DEC B, though.
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
thepenguin77
z80 Assembly Master
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 01:15:58
Date Registered: 14 December, 2009, 04:21:52
Location: Purdue
Posts: 1484


Topic starter
Total Post Ratings: +778

View Profile
« Reply #5 on: 18 January, 2012, 05:35:11 »
0

Brilliant

(And useless in 99% of cases)
Logged

zStart v1.3.011 4-29-2013  zStart fully works on 83+BE's (except custom font)
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112
Xeda112358
Xombie. I am it.
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Online Online

Last Login: Today at 02:33:47
Date Registered: 31 October, 2010, 08:46:36
Location: Land of Little Cubes and Tea, NY
Posts: 3759


Total Post Ratings: +609

View Profile
« Reply #6 on: 18 January, 2012, 05:36:29 »
0

It is one of those things that may not be used for a long time, but when it happens, somebody is going to feel special Big smile
Logged



Grammer Download (2.29.04.12)
Latest update (possibly incomplete)
My pastebin
Spoiler for FileSyst:
FileSyst is an application that provides a folder and filesystem for the TI-83+/84+ calculators. It is designed to be easy to access and use in BASIC, and it can be used to access game files and save data, or to create a command prompt, among other things:

Spoiler for Graphiti:
This is a graph explorer for graph theory. It will require lots of work to finish. Currently you can:
Add/delete vertices
Add edges (direction not shown, but they are directed)
Arrange vertices in a circle (in the future, you will be able to define levels of rings and the number of nodes in each)
Create complete graphs quickly

Plans:
Add adjacency matrix viewer
Deleting edges
Multiple graphs support
Arrows for directed graphs
Planarity testing
Matrix operations
Weighted edges
Chromatic polynomials
Chromatic numbers

Spoiler for Stats:

Samocal             [o---------]
Virtual Processor   [o---------]
EnG                 [oo--------]
Grammer             [ooo-------]
AsmComp             [ooo-------]
Partex              [oooo------]
BatLib              [oooooooo--]
Grammer82           [----------]
Grammer68000        [----------]


Pseudonyms:  Zeda, Xeda, Thunderbolt
Languages:   English, français
Programming: z80 Assmebly
             Grammer
             TI-BASIC (83/84/+/SE, 89/89t/92)
Known For:   -Creator of the Grammer programming language
              (Winning program of zContest2011)
             -BatLib- One of the most feature packed libraries for BASIC programmers available
              with over 100 functions and a simple programming language
             -Learning to program z80 in hexadecimal before using an assembler (no computer was
              available!)
╔═╦╗░╠═╬╣▒║ ║║▓╚═╩╝█


Jonius7
aka jhgenius
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 06:58:52
Date Registered: 03 September, 2010, 02:50:11
Location: Gold Coast, Australia
Posts: 1743


Total Post Ratings: +50

View Profile WWW
« Reply #7 on: 18 January, 2012, 05:40:43 »
0

That looks very nice, the djnz bundles dec, jr, nz nicely, saving space and adding efficiency. Could be useful, +1.
Logged



Userbars.com is down?
+9001
Intermediate TI-nspire Basic Programmer
Programmed some CASIO Basic in the past
DJ_O Music Discographist Wink
Userbars for these coming... in the process

My Released and Announced Projects (Updated 2013/01/29)
TI-nspire BASIC
TI-nspire Hold 'em | Health Bar | Scissors Paper Rock | Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled)

TI-nspire Lua
Numstrat | TI-nspire Hold 'em Lua | Terraria (coming soon)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Spoiler for Other Stuff:
Spoiler for Want your own HonestDownloads userbar?:
Hello! Do you want to show your affection for my website, HonestDownloads? Then here is a userbar I specially created earlier just for HonestDownloads users!

To add it to your signature just copy and paste the code below into your sig and you'll become an instant supporter of my website!

1
[URL=http://www.jhgenius01.webs.com][IMG]http://s1.bild.me/bilder/060112/3684792HDuserbaruser.png[/IMG][/URL]
Spoiler for My TI-nspire Basic Programs (Updated 2012/04/15):
***List of Programs in the TI-nspire Stadium***
Group Release 2012/04/07 on omnimaga.org

Games
   Noteable Release    ticalc.org Release Development/Not Publicly Released
2010/05/08 TI-nspire Hold 'em
   2012/04/07 v1.1.2   2012/04/10 v1.1.3  2012/04/14 v1.2.1
2010/08/03 Cosmic Legions
   2012/04/07 v0.2.2.2 (1st Release)
2010/08/12 Battle of 16s
   2012/04/07 v0.2.7
2010/09/10 Health Bar
   2012/04/07 v1.2     2012/04/02 v1.0   
2010/12/04 sTIck RPG
   2012/04/07 v0.1.5.2
2011/01/09 Monopoly
   2012/04/07 v0.16    (1st Release)
2012/04/09 Scissors Paper Rock
   2012/04/14 v0.8.1

Miscellaneous
2010/11/07 中文 (Chinese) Demonstration
   2012/04/07 v1.3     (1st Release)

Potential/Minor Programs
2010/09/26 Shanghai Metro
   2012/04/07 v0.2     (1st Release)
2010/12/22 TI-nspire Programming Tutorials
   2012/04/07 v0.1     (1st Release)
2010/12/28 Casino Games
   Was not released.
2011/04/22 Interlink
   2012/04/07 v0.0.4   (1st Release)
2012/03/22 Hierarchy
   2012/04/07 v0.01

Demo Programs (some may become Potential Programs)
2010/06/23 Monopoly (Board)
   2012/04/07 Prototype
2010/07/14 Strategy Battle
   2012/04/07 v0.12
2010/10/05 JRPG
   2012/04/07 v0.2
2010/11/02 PlotGrid
   2012/04/07 v0.2
2010/11/24 civilizaTIon™
   2012/04/07 v0.11

Purely Informational
2011/01/05 TI-nspire Stadium Changelog
   2012/04/07 v2
   Created to list significant releases of my programs. A page similar to this List of Programs in the TI-nspire Stadium was included in the documentation of most of my programs until sometime in Late 2011/Early 2012.

All games and programs coded in TI-nspire Basic.
© 2010-2012 Jason Ho.
Last Updated 14 April 2012

jhgenius01.webs.com
Will be moving! Stay tuned for updates.
Spoiler for Progress of Doodle God Axe:
2011/12/21 4% - Progress Suspended, ideas of graphical sprites still uncertain
Spoiler for Other Other You Know What Other Stuff I'm Talking About Stuff Stuff (Updated 2012/01/17):
chickendude
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Female
Last Login: 21 May, 2013, 19:04:07
Date Registered: 06 September, 2008, 11:27:30
Posts: 435

Total Post Ratings: +66

View Profile
« Reply #8 on: 19 January, 2012, 00:19:49 »
0

It's amazing how creative you all are. For the djnz list i usually just use a jump table and maybe push a return value onto the stack, but that looks like it'd be smaller (if not faster), though you'd have to be careful with 'b'.
Logged
All_¥our_Bass
LV1 Newcomer (Next: 20)
*
Offline Offline

Last Login: Yesterday at 20:33:52
Date Registered: 26 September, 2011, 23:17:18
Posts: 15


Total Post Ratings: +1

View Profile
« Reply #9 on: 29 January, 2012, 04:05:32 »
0

 ld b,0
for_loop:
;stuff here
 djnz for_loop
;will repeat 256 times
Logged

SOPA = Sons Of the Patriots Act

Stop SOPA
Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 00:07:45
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5642


Total Post Ratings: +589

View Profile
« Reply #10 on: 02 February, 2012, 07:21:57 »
0

I think the best DJNZ is to ONLY use DJNZ Cheesy I was reading about Single Instruction Set Computers and learned that using only DJNZ you can produce a turring complete language!
Logged

All_¥our_Bass
LV1 Newcomer (Next: 20)
*
Offline Offline

Last Login: Yesterday at 20:33:52
Date Registered: 26 September, 2011, 23:17:18
Posts: 15


Total Post Ratings: +1

View Profile
« Reply #11 on: 04 February, 2012, 02:37:34 »
0

I think the best DJNZ is to ONLY use DJNZ Cheesy I was reading about Single Instruction Set Computers and learned that using only DJNZ you can produce a turring complete language!
Mind = Blown
Logged

SOPA = Sons Of the Patriots Act

Stop SOPA
Jonius7
aka jhgenius
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 06:58:52
Date Registered: 03 September, 2010, 02:50:11
Location: Gold Coast, Australia
Posts: 1743


Total Post Ratings: +50

View Profile WWW
« Reply #12 on: 19 February, 2012, 21:58:22 »
0

What does turring complete language mean? especially the turring part.
Do you mean Turing, as for example, the Turing test?
« Last Edit: 19 February, 2012, 21:59:17 by Jonius7 » Logged



Userbars.com is down?
+9001
Intermediate TI-nspire Basic Programmer
Programmed some CASIO Basic in the past
DJ_O Music Discographist Wink
Userbars for these coming... in the process

My Released and Announced Projects (Updated 2013/01/29)
TI-nspire BASIC
TI-nspire Hold 'em | Health Bar | Scissors Paper Rock | Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled)

TI-nspire Lua
Numstrat | TI-nspire Hold 'em Lua | Terraria (coming soon)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Spoiler for Other Stuff:
Spoiler for Want your own HonestDownloads userbar?:
Hello! Do you want to show your affection for my website, HonestDownloads? Then here is a userbar I specially created earlier just for HonestDownloads users!

To add it to your signature just copy and paste the code below into your sig and you'll become an instant supporter of my website!

1
[URL=http://www.jhgenius01.webs.com][IMG]http://s1.bild.me/bilder/060112/3684792HDuserbaruser.png[/IMG][/URL]
Spoiler for My TI-nspire Basic Programs (Updated 2012/04/15):
***List of Programs in the TI-nspire Stadium***
Group Release 2012/04/07 on omnimaga.org

Games
   Noteable Release    ticalc.org Release Development/Not Publicly Released
2010/05/08 TI-nspire Hold 'em
   2012/04/07 v1.1.2   2012/04/10 v1.1.3  2012/04/14 v1.2.1
2010/08/03 Cosmic Legions
   2012/04/07 v0.2.2.2 (1st Release)
2010/08/12 Battle of 16s
   2012/04/07 v0.2.7
2010/09/10 Health Bar
   2012/04/07 v1.2     2012/04/02 v1.0   
2010/12/04 sTIck RPG
   2012/04/07 v0.1.5.2
2011/01/09 Monopoly
   2012/04/07 v0.16    (1st Release)
2012/04/09 Scissors Paper Rock
   2012/04/14 v0.8.1

Miscellaneous
2010/11/07 中文 (Chinese) Demonstration
   2012/04/07 v1.3     (1st Release)

Potential/Minor Programs
2010/09/26 Shanghai Metro
   2012/04/07 v0.2     (1st Release)
2010/12/22 TI-nspire Programming Tutorials
   2012/04/07 v0.1     (1st Release)
2010/12/28 Casino Games
   Was not released.
2011/04/22 Interlink
   2012/04/07 v0.0.4   (1st Release)
2012/03/22 Hierarchy
   2012/04/07 v0.01

Demo Programs (some may become Potential Programs)
2010/06/23 Monopoly (Board)
   2012/04/07 Prototype
2010/07/14 Strategy Battle
   2012/04/07 v0.12
2010/10/05 JRPG
   2012/04/07 v0.2
2010/11/02 PlotGrid
   2012/04/07 v0.2
2010/11/24 civilizaTIon™
   2012/04/07 v0.11

Purely Informational
2011/01/05 TI-nspire Stadium Changelog
   2012/04/07 v2
   Created to list significant releases of my programs. A page similar to this List of Programs in the TI-nspire Stadium was included in the documentation of most of my programs until sometime in Late 2011/Early 2012.

All games and programs coded in TI-nspire Basic.
© 2010-2012 Jason Ho.
Last Updated 14 April 2012

jhgenius01.webs.com
Will be moving! Stay tuned for updates.
Spoiler for Progress of Doodle God Axe:
2011/12/21 4% - Progress Suspended, ideas of graphical sprites still uncertain
Spoiler for Other Other You Know What Other Stuff I'm Talking About Stuff Stuff (Updated 2012/01/17):
Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 00:07:45
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5642


Total Post Ratings: +589

View Profile
« Reply #13 on: 19 February, 2012, 22:09:22 »
0

Turing Completeness is a computer science term referring to the ability of a language to complete problems.  If a language is Turing Complete, it is able to solve any problem a Turing computer could solve.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.48 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.