/*

Copyright (c) 2010 Andrea Fazzi

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

package z80

//
// Automatically generated file -- DO NOT EDIT
//


// Generated INC/DEC functions for 8bit registers

<%= %w{ A B C D E F H I L R7 A_ B_ C_ D_ E_ F_ H_ L_ IXL IXH IYL IYH }.inject("") do |result, reg|
  result += <<CODE

func (z80 *Z80) inc#{reg}() {
	z80.#{reg}++
	z80.F = ( z80.F & FLAG_C ) | ( ternOpB(z80.#{reg} == 0x80, FLAG_V, 0) ) | ( ternOpB((z80.#{reg} & 0x0f) != 0, 0, FLAG_H) ) | sz53Table[z80.#{reg}]
}

func (z80 *Z80) dec#{reg}() {
	z80.F = ( z80.F & FLAG_C ) | ( ternOpB(z80.#{reg} & 0x0f != 0, 0, FLAG_H )) | FLAG_N
	z80.#{reg}--
	z80.F |= ( ternOpB(z80.#{reg} == 0x7f, FLAG_V, 0) ) | sz53Table[z80.#{reg}]
}

CODE
end
%>


// Generated getters/setters and INC/DEC functions for 16bit registers

<%= %w{ bc de hl bc_ de_ hl_ ix iy }.inject("") do |result, reg|
  result += <<CODE

func (z80 *Z80) #{reg.upcase}() uint16 {
 	return z80.#{reg}.get()
}

func (z80 *Z80) Set#{reg.upcase}(value uint16) {
	z80.#{reg}.set(value)
}

func (z80 *Z80) Dec#{reg.upcase}() {
	z80.#{reg}.dec()
}

func (z80 *Z80) Inc#{reg.upcase}() {
	z80.#{reg}.inc()
}
CODE
end
%>
